diff --git a/src/http.cc b/src/http.cc index 6c344e5..95e75dc 100644 --- a/src/http.cc +++ b/src/http.cc @@ -2,6 +2,7 @@ #include "errors.h" #include "logging.h" +#include Json::Value taranis::HttpClient::get(const std::string &url) { BOOST_LOG_TRIVIAL(debug) << "Sending GET request " << url; @@ -29,12 +30,20 @@ Json::Value taranis::HttpClient::get(const std::string &url) { throw HttpError{response_code}; } + BOOST_LOG_TRIVIAL(debug) << "Received " << response_data.size() << " bytes"; + Json::Value root; - Json::Reader reader; - if (not reader.parse(response_data, root)) { - BOOST_LOG_TRIVIAL(error) - << "JSON parser error " << response_data << " " << url; - throw JsonParseError{}; + Json::CharReaderBuilder reader; + reader["collectComments"] = false; + std::string json_errors; + std::stringstream input_stream{response_data}; + try { + if (not Json::parseFromStream(reader, input_stream, &root, &json_errors)) { + BOOST_LOG_TRIVIAL(error) + << "JSON parser error " << json_errors << " " << url; + } + } catch (const Json::Exception& error) { + BOOST_LOG_TRIVIAL(error) << error.what(); } return root; } diff --git a/src/main.cc b/src/main.cc index 1fa7e1b..e64d1c6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -15,6 +15,9 @@ int event_handler(int event_type, int param_one, int param_two) { } catch (const std::logic_error &error) { BOOST_LOG_TRIVIAL(error) << "Unhandled logic error " << error.what(); throw; + } catch (const std::exception &error) { + BOOST_LOG_TRIVIAL(error) << "Unhandled error " << error.what(); + throw; } }