fix double ref and case of exceptions that are not std::exception

This commit is contained in:
Kai Aoki 2022-07-15 01:45:10 +09:00
parent 72d3f4896a
commit d4ab2fa0e6

View file

@ -616,7 +616,7 @@ public:
using Handler = std::function<void(const Request &, Response &)>;
using ExceptionHandler =
std::function<void(const Request &, Response &, std::exception_ptr &ep)>;
std::function<void(const Request &, Response &, std::exception_ptr ep)>;
enum class HandlerResponse {
Handled,
@ -5741,9 +5741,15 @@ Server::process_request(Stream &strm, bool close_connection,
res.set_header("EXCEPTION_WHAT", e.what());
}
} catch (...) {
if (exception_handler_) {
auto ep = std::current_exception();
exception_handler_(req, res, ep);
routed = true;
} else {
res.status = 500;
res.set_header("EXCEPTION_WHAT", "UNKNOWN");
}
}
#endif
if (routed) {