-
Notifications
You must be signed in to change notification settings - Fork 657
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
add one shot mode to valhalla_service #2624
Changes from all commits
58ac993
fddfb7f
d9e0770
9c211f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -961,6 +961,32 @@ void ParseApi(const std::string& request, Options::Action action, valhalla::Api& | |
from_json(document, *api.mutable_options()); | ||
} | ||
|
||
std::string jsonify_error(const valhalla_exception_t& exception, const Api& request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was pulled out of the service only method below and is now used when the actor methods throw, which is what the workers do. we could move the try catch inside the actor and have it handle it all but taht would require rewriting some unit tests and i didn twant to bite that off yet. we can leave that for the future |
||
// get the http status | ||
std::stringstream body; | ||
|
||
// overwrite with osrm error response | ||
if (request.options().format() == Options::osrm) { | ||
auto found = OSRM_ERRORS_CODES.find(exception.code); | ||
if (found == OSRM_ERRORS_CODES.cend()) { | ||
found = OSRM_ERRORS_CODES.find(199); | ||
} | ||
body << (request.options().has_jsonp() ? request.options().jsonp() + "(" : "") << found->second | ||
<< (request.options().has_jsonp() ? ")" : ""); | ||
} // valhalla error response | ||
else { | ||
// build up the json map | ||
auto json_error = baldr::json::map({}); | ||
json_error->emplace("status", exception.http_message); | ||
json_error->emplace("status_code", static_cast<uint64_t>(exception.http_code)); | ||
json_error->emplace("error", std::string(exception.message)); | ||
json_error->emplace("error_code", static_cast<uint64_t>(exception.code)); | ||
body << (request.options().has_jsonp() ? request.options().jsonp() + "(" : "") << *json_error | ||
<< (request.options().has_jsonp() ? ")" : ""); | ||
} | ||
return body.str(); | ||
} | ||
|
||
#ifdef HAVE_HTTP | ||
void ParseApi(const http_request_t& request, valhalla::Api& api) { | ||
api.Clear(); | ||
|
@@ -1032,31 +1058,9 @@ const headers_t::value_type ATTACHMENT{"Content-Disposition", "attachment; filen | |
worker_t::result_t jsonify_error(const valhalla_exception_t& exception, | ||
http_request_info_t& request_info, | ||
const Api& request) { | ||
// get the http status | ||
std::stringstream body; | ||
|
||
// overwrite with osrm error response | ||
if (request.options().format() == Options::osrm) { | ||
auto found = OSRM_ERRORS_CODES.find(exception.code); | ||
if (found == OSRM_ERRORS_CODES.cend()) { | ||
found = OSRM_ERRORS_CODES.find(199); | ||
} | ||
body << (request.options().has_jsonp() ? request.options().jsonp() + "(" : "") << found->second | ||
<< (request.options().has_jsonp() ? ")" : ""); | ||
} // valhalla error response | ||
else { | ||
// build up the json map | ||
auto json_error = baldr::json::map({}); | ||
json_error->emplace("status", exception.http_message); | ||
json_error->emplace("status_code", static_cast<uint64_t>(exception.http_code)); | ||
json_error->emplace("error", std::string(exception.message)); | ||
json_error->emplace("error_code", static_cast<uint64_t>(exception.code)); | ||
body << (request.options().has_jsonp() ? request.options().jsonp() + "(" : "") << *json_error | ||
<< (request.options().has_jsonp() ? ")" : ""); | ||
} | ||
|
||
worker_t::result_t result{false, std::list<std::string>(), ""}; | ||
http_response_t response(exception.http_code, exception.http_message, body.str(), | ||
http_response_t response(exception.http_code, exception.http_message, | ||
jsonify_error(exception, request), | ||
headers_t{CORS, request.options().has_jsonp() ? worker::JS_MIME | ||
: worker::JSON_MIME}); | ||
response.from_info(request_info); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,16 +151,8 @@ void ParseApi(const std::string& json_request, Options::Action action, Api& api) | |
void ParseApi(const prime_server::http_request_t& http_request, Api& api); | ||
#endif | ||
|
||
std::string jsonify_error(const valhalla_exception_t& exception, const Api& options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the only real change. just moved the other thing down so the jsonify methods would be closer together |
||
#ifdef HAVE_HTTP | ||
|
||
namespace worker { | ||
using content_type = prime_server::headers_t::value_type; | ||
const content_type JSON_MIME{"Content-type", "application/json;charset=utf-8"}; | ||
const content_type JS_MIME{"Content-type", "application/javascript;charset=utf-8"}; | ||
const content_type XML_MIME{"Content-type", "text/xml;charset=utf-8"}; | ||
const content_type GPX_MIME{"Content-type", "application/gpx+xml;charset=utf-8"}; | ||
} // namespace worker | ||
|
||
prime_server::worker_t::result_t jsonify_error(const valhalla_exception_t& exception, | ||
prime_server::http_request_info_t& request_info, | ||
const Api& options); | ||
|
@@ -170,6 +162,14 @@ prime_server::worker_t::result_t to_response(const baldr::json::ArrayPtr& array, | |
prime_server::worker_t::result_t to_response(const baldr::json::MapPtr& map, | ||
prime_server::http_request_info_t& request_info, | ||
const Api& options); | ||
namespace worker { | ||
using content_type = prime_server::headers_t::value_type; | ||
const content_type JSON_MIME{"Content-type", "application/json;charset=utf-8"}; | ||
const content_type JS_MIME{"Content-type", "application/javascript;charset=utf-8"}; | ||
const content_type XML_MIME{"Content-type", "text/xml;charset=utf-8"}; | ||
const content_type GPX_MIME{"Content-type", "application/gpx+xml;charset=utf-8"}; | ||
} // namespace worker | ||
|
||
prime_server::worker_t::result_t | ||
to_response(const std::string& data, | ||
prime_server::http_request_info_t& request_info, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build it no matter what