Mercurial > irccd
comparison irccdctl/cli.cpp @ 569:24b79bccc181
Irccd: initial support of error code responses
Bring several new types for describing precise errors using:
- irccd_error: for general errors including connecting/recv/send,
- server_error: server and server_service,
- rule_error: rule and rule_service,
- plugin_error: plugin and plugin_service.
No error string are sent to the client anymore.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 28 Nov 2017 13:57:09 +0100 |
parents | 1ef194b6b168 |
children | 27587ff92a64 |
comparison
equal
deleted
inserted
replaced
568:ed986ae52656 | 569:24b79bccc181 |
---|---|
17 */ | 17 */ |
18 | 18 |
19 #include <boost/system/system_error.hpp> | 19 #include <boost/system/system_error.hpp> |
20 | 20 |
21 #include <irccd/json_util.hpp> | 21 #include <irccd/json_util.hpp> |
22 #include <irccd/network_errc.hpp> | |
23 #include <irccd/options.hpp> | 22 #include <irccd/options.hpp> |
24 #include <irccd/string_util.hpp> | 23 #include <irccd/string_util.hpp> |
25 | 24 |
26 #include <irccd/ctl/controller.hpp> | 25 #include <irccd/ctl/controller.hpp> |
27 | 26 |
34 void cli::recv_response(ctl::controller& ctl, nlohmann::json req, handler_t handler) | 33 void cli::recv_response(ctl::controller& ctl, nlohmann::json req, handler_t handler) |
35 { | 34 { |
36 ctl.recv([&ctl, req, handler, this] (auto code, auto message) { | 35 ctl.recv([&ctl, req, handler, this] (auto code, auto message) { |
37 if (code) | 36 if (code) |
38 throw boost::system::system_error(code); | 37 throw boost::system::system_error(code); |
39 | |
40 if (message["error"].is_number_integer()) | |
41 throw boost::system::system_error(static_cast<network_errc>(message["error"].template get<int>())); | |
42 if (message["error"].is_string()) | |
43 throw std::runtime_error(message["error"].template get<std::string>()); | |
44 | 38 |
45 auto c = json_util::to_string(message["command"]); | 39 auto c = json_util::to_string(message["command"]); |
46 | 40 |
47 if (c != req["command"].get<std::string>()) { | 41 if (c != req["command"].get<std::string>()) { |
48 recv_response(ctl, std::move(req), std::move(handler)); | 42 recv_response(ctl, std::move(req), std::move(handler)); |