summaryrefslogtreecommitdiffstats
path: root/include/exceptions.hpp
blob: 9e51d9759d25c09699bd3d936c7a08cbc05d9101 (plain)
1
2
3
4
5
6
7
8
9
10
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.St
/*  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