summaryrefslogtreecommitdiffstats
path: root/include/exceptions.hpp
blob: 9e51d9759d25c09699bd3d936c7a08cbc05d9101 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*  This file is part of mastodonpp.
 *  Copyright © 2020 tastytea <tastytea@tastytea.de>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, version 3.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MASTODONPP_EXCEPTIONS_HPP
#define MASTODONPP_EXCEPTIONS_HPP

#include <curl/curl.h>

#include <cstdint>
#include <exception>
#include <string>

namespace mastodonpp
{

using std::uint16_t;
using std::exception;
using std::string;

/*!
 *  @brief  Exception for libcurl errors.
 *
 *  @since  0.1.0
 *
 *  @headerfile exceptions.hpp mastodonpp/exceptions.hpp
 */
class CURLException : public exception
{
public:
    /*!
     *  @brief  Constructor with error code and message.
     *
     *  @since  0.1.0
     */
    explicit CURLException(const CURLcode &error, string message);

    /*!
     *  @brief Constructor with error code, message and error buffer.
     *
     *  @since  0.1.0
     */
    explicit CURLException(const CURLcode &error, string message,
                           string error_buffer);

    /*!
     *  @brief  The error code returned by libcurl.
     *
     *  For more information consult
     *  [libcurl-errors(3)](https://curl.haxx.se/libcurl/c/libcurl-errors.html).
     *
     *  @since  0.1.0
     */
    const CURLcode error_code;

    /*!
     *  @brief  Returns the error code, message and error buffer.
     *
     *  @since  0.1.0
     */
    [[nodiscard]]
    const char *what() const noexcept override;

private:
    const string _message;
    const string _error_buffer;
};

} // namespace mastodonpp

#endif  // MASTODONPP_EXCEPTIONS_HPP