Skip to content

Commit

Permalink
Merge branch 'fix/json-body-check'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Jul 10, 2024
2 parents fb74026 + f251a6f commit bc29414
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/routing/http_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Location>& locs) const {
Expand Down
19 changes: 17 additions & 2 deletions src/routing/ors_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,23 @@ void OrsWrapper::check_response(const rapidjson::Document& json_result,
const std::vector<Location>&,
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);
}
}
}

Expand Down

0 comments on commit bc29414

Please sign in to comment.