forked from loafle/openapi-generator-original
[C++][Pistache] Catch HttpError from user-provided handler (#6520)
* [C++][Pistache] Catch HttpError when user-provided handler has thrown This allows for returning valid http code through exception * [C++][Pistache] Update Petstore sample
This commit is contained in:
committed by
GitHub
parent
d5ea62f966
commit
c102ced044
@@ -51,6 +51,9 @@ void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pist
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
@@ -66,6 +69,9 @@ void StoreApi::get_inventory_handler(const Pistache::Rest::Request &, Pistache::
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
@@ -83,6 +89,9 @@ void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, P
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
@@ -103,6 +112,9 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
|
||||
Reference in New Issue
Block a user