OpenVPN 3 Core Library
Loading...
Searching...
No Matches
webexcept.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_HTTP_EXCEPT_H
13#define OPENVPN_HTTP_EXCEPT_H
14
15#include <string>
16#include <sstream>
17#include <exception>
18
20
21#define OPENVPN_THROW_WEB(exc, status, stuff) \
22 do \
23 { \
24 std::ostringstream _ovpn_exc; \
25 _ovpn_exc << stuff; \
26 throw exc(status, _ovpn_exc.str()); \
27 } while (0)
28
29namespace openvpn::HTTP {
30class WebException : public std::exception
31{
32 public:
33 WebException(const int status, const std::string &error)
34 : status_(status),
36 formatted(std::string(Status::to_string(status_)) + " : " + error_)
37 {
38 }
39
41 : status_(status),
42 error_(Status::to_string(status_)),
44 {
45 }
46
47 int status() const
48 {
49 return status_;
50 }
51 const std::string &error() const
52 {
53 return error_;
54 }
55
56 const char *what() const noexcept override
57 {
58 return formatted.c_str();
59 }
60
61 private:
62 const int status_;
63 const std::string error_;
64 const std::string formatted;
65};
66} // namespace openvpn::HTTP
67
68#endif
const std::string error_
Definition webexcept.hpp:63
const char * what() const noexcept override
Definition webexcept.hpp:56
const std::string formatted
Definition webexcept.hpp:64
WebException(const int status, const std::string &error)
Definition webexcept.hpp:33
const std::string & error() const
Definition webexcept.hpp:51
WebException(const int status)
Definition webexcept.hpp:40