Skip to content

Commit

Permalink
http: Change exception formating to the generic seastar one
Browse files Browse the repository at this point in the history
It is beneficial to get the full context that an exception
can provide. When http translates an exception into an
http responce json, it ignored the case of nested exception
and always printed the last exception.
This patch makes use of seastars ability to print out exception
to the log along with types and nested exceptions information.

Signed-off-by: Eliran Sinvani <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
Eliran Sinvani authored and nyh committed Dec 19, 2019
1 parent 0bde519 commit 9612a94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 5 additions & 3 deletions include/seastar/http/exception.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#pragma once

#include <seastar/util/log.hh>
#include <seastar/http/reply.hh>
#include <seastar/json/json_elements.hh>

Expand Down Expand Up @@ -124,8 +124,10 @@ public:
set(e.str(), e.status());
}

json_exception(const std::exception& e) {
set(e.what(), reply::status_type::internal_server_error);
json_exception(std::exception_ptr e) {
std::ostringstream exception_description;
exception_description << e;
set(exception_description.str(), reply::status_type::internal_server_error);
}
private:
void set(const std::string& msg, reply::status_type code) {
Expand Down
7 changes: 2 additions & 5 deletions src/http/routes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ std::unique_ptr<reply> routes::exception_reply(std::exception_ptr eptr) {
std::rethrow_exception(eptr);
} catch (const base_exception& e) {
rep->set_status(e.status(), json_exception(e).to_json());
} catch (exception& e) {
rep->set_status(reply::status_type::internal_server_error,
json_exception(e).to_json());
} catch (...) {
rep->set_status(reply::status_type::internal_server_error,
json_exception(std::runtime_error(
"Unknown unhandled exception")).to_json());
json_exception(std::current_exception()).to_json());
}

rep->done("json");
return rep;
}
Expand Down

0 comments on commit 9612a94

Please sign in to comment.