From d4ab2fa0e6a1f903a5f4be761d1f1ed5e4aaee8c Mon Sep 17 00:00:00 2001 From: Kai Aoki Date: Fri, 15 Jul 2022 01:45:10 +0900 Subject: [PATCH] fix double ref and case of exceptions that are not std::exception --- httplib.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/httplib.h b/httplib.h index 111276a..7647fed 100644 --- a/httplib.h +++ b/httplib.h @@ -616,7 +616,7 @@ public: using Handler = std::function; using ExceptionHandler = - std::function; + std::function; enum class HandlerResponse { Handled, @@ -5741,8 +5741,14 @@ Server::process_request(Stream &strm, bool close_connection, res.set_header("EXCEPTION_WHAT", e.what()); } } catch (...) { - res.status = 500; - res.set_header("EXCEPTION_WHAT", "UNKNOWN"); + 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