diff --git a/CHANGELOG.md b/CHANGELOG.md index eddf05e5f..46ff37acc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,10 @@ - Wrong compiler used for clang-based OSRM builds (#1098) +#### Routing + +- ORS error handling (#1083) + ## [v1.14.0] - 2024-01-16 ### Added diff --git a/src/routing/http_wrapper.cpp b/src/routing/http_wrapper.cpp index 63847232b..e53ab3e0c 100644 --- a/src/routing/http_wrapper.cpp +++ b/src/routing/http_wrapper.cpp @@ -141,11 +141,10 @@ std::string HttpWrapper::run_query(const std::string& query) const { void HttpWrapper::parse_response(rapidjson::Document& json_result, const std::string& json_content) { -#ifdef NDEBUG json_result.Parse(json_content.c_str()); -#else - assert(!json_result.Parse(json_content.c_str()).HasParseError()); -#endif + if (json_result.HasParseError()) { + throw RoutingException("Failed to parse routing response."); + } } Matrices HttpWrapper::get_matrices(const std::vector& locs) const { diff --git a/src/routing/ors_wrapper.cpp b/src/routing/ors_wrapper.cpp index b9dbb6fa5..15658b0f3 100644 --- a/src/routing/ors_wrapper.cpp +++ b/src/routing/ors_wrapper.cpp @@ -64,8 +64,23 @@ void OrsWrapper::check_response(const rapidjson::Document& json_result, const std::vector&, const std::string&) const { if (json_result.HasMember("error")) { - throw RoutingException( - std::string(json_result["error"]["message"].GetString())); + if (json_result["error"].IsObject() && + json_result["error"].HasMember("message") && + json_result["error"]["message"].IsString()) { + // Normal ORS error syntax. + throw RoutingException( + std::string(json_result["error"]["message"].GetString())); + } + + if (json_result["error"].IsString()) { + // Web framework error uses another convention, see #1083. + auto error = std::string(json_result["error"].GetString()); + + if (json_result.HasMember("path") && json_result["path"].IsString()) { + error += " " + std::string(json_result["path"].GetString()); + } + throw RoutingException(error); + } } }