mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 01:33:53 +00:00
simplest way to catch handler exceptions
This commit is contained in:
parent
6e473a7c5c
commit
e07c5fec01
@ -3462,6 +3462,8 @@ inline bool Server::routing(Request &req, Response &res, Stream &strm,
|
|||||||
|
|
||||||
inline bool Server::dispatch_request(Request &req, Response &res,
|
inline bool Server::dispatch_request(Request &req, Response &res,
|
||||||
Handlers &handlers) {
|
Handlers &handlers) {
|
||||||
|
|
||||||
|
try {
|
||||||
for (const auto &x : handlers) {
|
for (const auto &x : handlers) {
|
||||||
const auto &pattern = x.first;
|
const auto &pattern = x.first;
|
||||||
const auto &handler = x.second;
|
const auto &handler = x.second;
|
||||||
@ -3471,6 +3473,13 @@ inline bool Server::dispatch_request(Request &req, Response &res,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (const std::exception &ex) {
|
||||||
|
res.status = 500;
|
||||||
|
res.set_header("EXCEPTION_WHAT", ex.what());
|
||||||
|
} catch (...) {
|
||||||
|
res.status = 500;
|
||||||
|
res.set_header("EXCEPTION_WHAT", "UNKNOWN");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user