pornsieve  0.0.0
Search porn sites and filter the results using regular expressions
exceptions.hpp
Go to the documentation of this file.
1 /* This file is part of pornsieve.
2  * Copyright © 2021 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
23 #ifndef PORNSIEVE_EXCEPTIONS_HPP
24 #define PORNSIEVE_EXCEPTIONS_HPP
25 
26 #include <curl/curl.h>
27 
28 #include <cstdint>
29 #include <exception>
30 #include <string>
31 #include <string_view>
32 
33 namespace pornsieve
34 {
35 
36 using std::string;
37 using std::string_view;
38 using std::uint16_t;
39 
45 class CURLException : public std::exception
46 {
47 public:
53  explicit CURLException(const CURLcode code)
54  : error_code{code}
55  {}
56 
62  explicit CURLException(const CURLcode code, string_view error_buffer)
63  : error_code{code}
64  , error_message{error_buffer}
65  {}
66 
67  const CURLcode error_code;
68  const string error_message;
69 
75  [[nodiscard]] const char *what() const noexcept override;
76 };
77 
83 class HTTPException : public std::exception
84 {
85 
86 public:
92  explicit HTTPException(const uint16_t code)
93  : error_code{code}
94  {}
95 
101  explicit HTTPException(const uint16_t code, string_view error_message)
102  : error_code{code}
103  , _error_message{error_message}
104  {}
105 
106  const uint16_t error_code;
107 
113  [[nodiscard]] const char *what() const noexcept override;
114 
115 private:
116  string _error_message;
117 };
118 
119 } // namespace pornsieve
120 
121 #endif // PORNSIEVE_EXCEPTIONS_HPP
pornsieve::HTTPException::error_code
const uint16_t error_code
HTTP status code.
Definition: exceptions.hpp:106
pornsieve
The namespace containing the pornsieve library.
Definition: config.hpp:30
pornsieve::CURLException
Exception for libcurl errors.
Definition: exceptions.hpp:45
pornsieve::CURLException::CURLException
CURLException(const CURLcode code, string_view error_buffer)
Constructor with error code and error message.
Definition: exceptions.hpp:62
pornsieve::HTTPException::HTTPException
HTTPException(const uint16_t code, string_view error_message)
Constructor with error code and error message.
Definition: exceptions.hpp:101
pornsieve::HTTPException
Exception for HTTP errors.
Definition: exceptions.hpp:83
pornsieve::CURLException::error_message
const string error_message
The error message.
Definition: exceptions.hpp:68
pornsieve::CURLException::error_code
const CURLcode error_code
Error code from libcurl.
Definition: exceptions.hpp:67
pornsieve::HTTPException::HTTPException
HTTPException(const uint16_t code)
Constructor with error code.
Definition: exceptions.hpp:92
pornsieve::CURLException::what
const char * what() const noexcept override
Error message.
Definition: exceptions.cpp:30
pornsieve::CURLException::CURLException
CURLException(const CURLcode code)
Constructor with error code.
Definition: exceptions.hpp:53