Skip to content

Commit bc29414

Browse files
committed
Merge branch 'fix/json-body-check'
2 parents fb74026 + f251a6f commit bc29414

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
- Wrong compiler used for clang-based OSRM builds (#1098)
3131

32+
#### Routing
33+
34+
- ORS error handling (#1083)
35+
3236
## [v1.14.0] - 2024-01-16
3337

3438
### Added

src/routing/http_wrapper.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ std::string HttpWrapper::run_query(const std::string& query) const {
141141

142142
void HttpWrapper::parse_response(rapidjson::Document& json_result,
143143
const std::string& json_content) {
144-
#ifdef NDEBUG
145144
json_result.Parse(json_content.c_str());
146-
#else
147-
assert(!json_result.Parse(json_content.c_str()).HasParseError());
148-
#endif
145+
if (json_result.HasParseError()) {
146+
throw RoutingException("Failed to parse routing response.");
147+
}
149148
}
150149

151150
Matrices HttpWrapper::get_matrices(const std::vector<Location>& locs) const {

src/routing/ors_wrapper.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,23 @@ void OrsWrapper::check_response(const rapidjson::Document& json_result,
6464
const std::vector<Location>&,
6565
const std::string&) const {
6666
if (json_result.HasMember("error")) {
67-
throw RoutingException(
68-
std::string(json_result["error"]["message"].GetString()));
67+
if (json_result["error"].IsObject() &&
68+
json_result["error"].HasMember("message") &&
69+
json_result["error"]["message"].IsString()) {
70+
// Normal ORS error syntax.
71+
throw RoutingException(
72+
std::string(json_result["error"]["message"].GetString()));
73+
}
74+
75+
if (json_result["error"].IsString()) {
76+
// Web framework error uses another convention, see #1083.
77+
auto error = std::string(json_result["error"].GetString());
78+
79+
if (json_result.HasMember("path") && json_result["path"].IsString()) {
80+
error += " " + std::string(json_result["path"].GetString());
81+
}
82+
throw RoutingException(error);
83+
}
6984
}
7085
}
7186

0 commit comments

Comments
 (0)