comparison irccdctl/cli.cpp @ 543:7051034bf2ee

Irccdctl: abort in case of error
author David Demelier <markand@malikania.fr>
date Tue, 21 Nov 2017 13:40:39 +0100
parents 80c3caafe9d3
children 1ef194b6b168
comparison
equal deleted inserted replaced
542:80c3caafe9d3 543:7051034bf2ee
35 { 35 {
36 ctl.recv([&ctl, req, handler, this] (auto code, auto message) { 36 ctl.recv([&ctl, req, handler, this] (auto code, auto message) {
37 if (code) 37 if (code)
38 throw boost::system::system_error(code); 38 throw boost::system::system_error(code);
39 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
40 auto c = json_util::to_string(message["command"]); 45 auto c = json_util::to_string(message["command"]);
41 46
42 if (c != req["command"].get<std::string>()) { 47 if (c != req["command"].get<std::string>()) {
43 recv_response(ctl, std::move(req), std::move(handler)); 48 recv_response(ctl, std::move(req), std::move(handler));
44 return; 49 return;
45 } 50 }
46
47 if (message["error"].is_number_integer())
48 throw boost::system::system_error(static_cast<network_errc>(message["error"].template get<int>()));
49 if (message["error"].is_string())
50 throw std::runtime_error(message["error"].template get<std::string>());
51 51
52 if (handler) 52 if (handler)
53 handler(std::move(message)); 53 handler(std::move(message));
54 }); 54 });
55 } 55 }