diff options
| author | Dan Engelbrecht <[email protected]> | 2024-04-04 14:32:40 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-04-04 14:32:40 +0200 |
| commit | 12b7bf1c16f671c83840961c37a339141a7ffbb3 (patch) | |
| tree | 3c503e6e1cd4d53b87c1baebcf9286ca8b72db06 /src/zenhttp/servers/httpasio.cpp | |
| parent | hardening parsepackagemessage (#38) (diff) | |
| download | zen-12b7bf1c16f671c83840961c37a339141a7ffbb3.tar.xz zen-12b7bf1c16f671c83840961c37a339141a7ffbb3.zip | |
improved assert (#37)
- Improvement: Add file and line to ASSERT exceptions
- Improvement: Catch call stack when throwing assert exceptions and log/output call stack at important places to provide more context to caller
Diffstat (limited to 'src/zenhttp/servers/httpasio.cpp')
| -rw-r--r-- | src/zenhttp/servers/httpasio.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/zenhttp/servers/httpasio.cpp b/src/zenhttp/servers/httpasio.cpp index de71eb0a7..cddbe1ae2 100644 --- a/src/zenhttp/servers/httpasio.cpp +++ b/src/zenhttp/servers/httpasio.cpp @@ -476,7 +476,15 @@ HttpServerConnection::HandleRequest() { Service->HandleRequest(Request); } - catch (std::system_error& SystemError) + catch (const AssertException& AssertEx) + { + // Drop any partially formatted response + Request.m_Response.reset(); + + ZEN_ERROR("Caught assert exception while handling request: {}", AssertEx.FullDescription()); + Request.WriteResponse(HttpResponseCode::InternalServerError, HttpContentType::kText, AssertEx.FullDescription()); + } + catch (const std::system_error& SystemError) { // Drop any partially formatted response Request.m_Response.reset(); @@ -491,14 +499,14 @@ HttpServerConnection::HandleRequest() Request.WriteResponse(HttpResponseCode::InternalServerError, HttpContentType::kText, SystemError.what()); } } - catch (std::bad_alloc& BadAlloc) + catch (const std::bad_alloc& BadAlloc) { // Drop any partially formatted response Request.m_Response.reset(); Request.WriteResponse(HttpResponseCode::InsufficientStorage, HttpContentType::kText, BadAlloc.what()); } - catch (std::exception& ex) + catch (const std::exception& ex) { // Drop any partially formatted response Request.m_Response.reset(); @@ -958,7 +966,11 @@ HttpAsioServerImpl::Start(uint16_t Port, bool ForceLooopback, int ThreadCount) { m_IoService.run(); } - catch (std::exception& e) + catch (const AssertException& AssertEx) + { + ZEN_ERROR("Assert caught in asio event loop: {}", AssertEx.FullDescription()); + } + catch (const std::exception& e) { ZEN_ERROR("Exception caught in asio event loop: '{}'", e.what()); } @@ -1075,7 +1087,7 @@ HttpAsioServer::Close() { m_Impl->Stop(); } - catch (std::exception& ex) + catch (const std::exception& ex) { ZEN_WARN("Caught exception stopping http asio server: {}", ex.what()); } |