Mercurial > irccd
changeset 538:5c92ebd4423c
Irccd: share error code
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 20 Nov 2017 19:16:43 +0100 |
parents | a4193cbce05d |
children | 63f504283797 |
files | libirccd/irccd/transport_client.cpp libirccd/irccd/transport_client.hpp libirccd/irccd/transport_server.cpp |
diffstat | 3 files changed, 4 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/libirccd/irccd/transport_client.cpp Sun Nov 19 09:16:05 2017 +0100 +++ b/libirccd/irccd/transport_client.cpp Mon Nov 20 19:16:43 2017 +0100 @@ -88,11 +88,11 @@ auto json = nlohmann::json::parse(message); if (!json.is_object()) - handler(nullptr, transport_error::invalid_message); + handler(nullptr, network_error::invalid_message); else handler(json, code); } catch (...) { - handler(nullptr, transport_error::invalid_message); + handler(nullptr, network_error::invalid_message); } }); } @@ -126,44 +126,4 @@ set_state(state_t::closing); } -/* - * transport_category - * ------------------------------------------------------------------ - */ -const boost::system::error_category& transport_category() noexcept -{ - static const class category : public boost::system::error_category { - public: - const char* name() const noexcept override - { - return "transport"; - } - - std::string message(int e) const override - { - switch (static_cast<transport_error>(e)) { - case transport_error::invalid_auth: - return "invalid authentication"; - case transport_error::invalid_message: - return "invalid message"; - case transport_error::incomplete_message: - return "incomplete message"; - } - - return "unknown error"; - } - } cat; - - return cat; -} - -/* - * make_error_code - * ------------------------------------------------------------------ - */ -boost::system::error_code make_error_code(transport_error e) noexcept -{ - return {static_cast<int>(e), transport_category()}; -} - } // !irccd
--- a/libirccd/irccd/transport_client.hpp Sun Nov 19 09:16:05 2017 +0100 +++ b/libirccd/irccd/transport_client.hpp Mon Nov 20 19:16:43 2017 +0100 @@ -37,15 +37,6 @@ class transport_server; /** - * \brief Error for transports. - */ -enum class transport_error : int { - invalid_auth = 1, //! invalid authentication - invalid_message, //! client has sent an invalid message - incomplete_message //!< message requires more parameter -}; - -/** * \brief Abstract transport client class. * * This class is responsible of receiving/sending data. @@ -363,33 +354,6 @@ } }; -/** - * Get the transport category. - * - * \return the singleton category - */ -const boost::system::error_category& transport_category() noexcept; - -/** - * Wrap the creation of an error_code based on transport_server::error. - * - * \param e the transport_server error code - * \return a boost::system::error_code with transport_category - */ -boost::system::error_code make_error_code(transport_error e) noexcept; - } // !irccd -namespace boost { - -namespace system { - -template <> -struct is_error_code_enum<irccd::transport_error> : public std::true_type { -}; - -} // !system - -} // !boost - #endif // !IRCCD_TRANSPORT_CLIENT_HPP
--- a/libirccd/irccd/transport_server.cpp Sun Nov 19 09:16:05 2017 +0100 +++ b/libirccd/irccd/transport_server.cpp Mon Nov 20 19:16:43 2017 +0100 @@ -36,12 +36,12 @@ auto password = message["password"]; if (!command.is_string() || !password.is_string()) { - handler(nullptr, transport_error::incomplete_message); + handler(nullptr, network_error::invalid_message); return false; } if (command != "auth" || password.get<std::string>() != password_) { - handler(nullptr, transport_error::invalid_auth); + handler(nullptr, network_error::invalid_auth); return false; }