server : add try..catch to places not covered by set_exception_handler (#11620)
* server : add try..catch to places not covered by set_exception_handler * log_server_request: rm try catch, add reminder
This commit is contained in:
parent
1bef571f6a
commit
3962fc1a79
1 changed files with 9 additions and 3 deletions
|
@ -3353,6 +3353,8 @@ static void log_server_request(const httplib::Request & req, const httplib::Resp
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reminder: this function is not covered by httplib's exception handler; if someone does more complicated stuff, think about wrapping it in try-catch
|
||||||
|
|
||||||
LOG_INF("request: %s %s %s %d\n", req.method.c_str(), req.path.c_str(), req.remote_addr.c_str(), res.status);
|
LOG_INF("request: %s %s %s %d\n", req.method.c_str(), req.path.c_str(), req.remote_addr.c_str(), res.status);
|
||||||
|
|
||||||
LOG_DBG("request: %s\n", req.body.c_str());
|
LOG_DBG("request: %s\n", req.body.c_str());
|
||||||
|
@ -3439,9 +3441,13 @@ int main(int argc, char ** argv) {
|
||||||
message = "Unknown Exception";
|
message = "Unknown Exception";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
json formatted_error = format_error_response(message, ERROR_TYPE_SERVER);
|
json formatted_error = format_error_response(message, ERROR_TYPE_SERVER);
|
||||||
LOG_WRN("got exception: %s\n", formatted_error.dump().c_str());
|
LOG_WRN("got exception: %s\n", formatted_error.dump().c_str());
|
||||||
res_error(res, formatted_error);
|
res_error(res, formatted_error);
|
||||||
|
} catch (const std::exception & e) {
|
||||||
|
LOG_ERR("got another exception: %s | while hanlding exception: %s\n", e.what(), message.c_str());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
svr->set_error_handler([&res_error](const httplib::Request &, httplib::Response & res) {
|
svr->set_error_handler([&res_error](const httplib::Request &, httplib::Response & res) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue