Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch exception when trying to connect to OSRM #288

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/osrmgeofilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,26 @@ namespace TrRouting {
queryString += "&sources=0";
}

using HttpClient = SimpleWeb::Client<SimpleWeb::HTTP>;
HttpClient client(host + ":" + port);
auto s = client.request("GET", queryString);

if (s->status_code != "200 OK") {
spdlog::error("Error fetching OSRM data ({})", s->status_code);
//TODO We should throw an exception somehow here to invalidate the current calculation
// and returne an informative error code to the user
std::stringstream responseJsonSs;
try {
using HttpClient = SimpleWeb::Client<SimpleWeb::HTTP>;
HttpClient client(host + ":" + port);
auto s = client.request("GET", queryString);

if (s->status_code != "200 OK") {
spdlog::error("Error fetching OSRM data ({})", s->status_code);
//TODO We should throw an exception somehow here to invalidate the current calculation
// and returne an informative error code to the user
return accessibleNodesFootpaths;
}

responseJsonSs << s->content.rdbuf();
} catch (const std::exception& e){
spdlog::error("exception during OSRM request: {}", e.what());
//TODO See above TODO about handling the errors
return accessibleNodesFootpaths;
}

std::stringstream responseJsonSs;
responseJsonSs << s->content.rdbuf();
nlohmann::json responseJson = nlohmann::json::parse(responseJsonSs.str());

if (responseJson["durations"] != nullptr && responseJson["distances"] != nullptr && responseJson["durations"][0] != nullptr && responseJson["distances"][0] != nullptr)
Expand Down
Loading