3#include "magpie/logger/Logger.hpp"
4#include "magpie/transfer/Response.hpp"
5#include "magpie/transfer/StatusCode.hpp"
9namespace magpie::utility {
11inline void defaultErrorResponse(Response* res) {
17 Status::InternalServerError,
18 "Unexpected error. Try again later."
34inline void runWithErrorLogging(
35 const std::function<
void()>& errorHandled,
36 Response* res =
nullptr
41 }
catch (
const std::exception& e) {
43 "Uncaught exception: {}", e.what()
45 defaultErrorResponse(res);
46 }
catch (
const std::string& e) {
48 "Uncaught {{str}}exception: {}", e
50 defaultErrorResponse(res);
56 "Uncaught exception of unknown type (cannot log)"
58 defaultErrorResponse(res);