MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / ex_wrapper

Function ex_wrapper

tools/server/server.cpp:40–72  ·  view source on GitHub ↗

wrapper function that handles exceptions and logs errors this is to make sure handler_t never throws exceptions; instead, it returns an error response

Source from the content-addressed store, hash-verified

38// wrapper function that handles exceptions and logs errors
39// this is to make sure handler_t never throws exceptions; instead, it returns an error response
40static server_http_context::handler_t ex_wrapper(server_http_context::handler_t func) {
41 return [func = std::move(func)](const server_http_req & req) -> server_http_res_ptr {
42 std::string message;
43 error_type error;
44 try {
45 return func(req);
46 } catch (const std::invalid_argument & e) {
47 // treat invalid_argument as invalid request (400)
48 error = ERROR_TYPE_INVALID_REQUEST;
49 message = e.what();
50 } catch (const std::exception & e) {
51 // treat other exceptions as server error (500)
52 error = ERROR_TYPE_SERVER;
53 message = e.what();
54 } catch (...) {
55 error = ERROR_TYPE_SERVER;
56 message = "unknown error";
57 }
58
59 auto res = std::make_unique<server_http_res>();
60 res->status = 500;
61 try {
62 json error_data = format_error_response(message, error);
63 res->status = json_value(error_data, "code", 500);
64 res->data = safe_json_to_str({{ "error", error_data }});
65 SRV_WRN("got exception: %s\n", res->data.c_str());
66 } catch (const std::exception & e) {
67 SRV_ERR("got another exception: %s | while handling exception: %s\n", e.what(), message.c_str());
68 res->data = "Internal Server Error";
69 }
70 return res;
71 };
72}
73
74int main(int argc, char ** argv) {
75 std::setlocale(LC_NUMERIC, "C");

Callers 1

mainFunction · 0.85

Calls 4

format_error_responseFunction · 0.85
json_valueFunction · 0.85
safe_json_to_strFunction · 0.85
whatMethod · 0.45

Tested by

no test coverage detected