mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 00:43:46 +00:00
[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
@@ -58,6 +58,9 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
|
||||
//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());
|
||||
@@ -78,6 +81,9 @@ void PetApi::delete_pet_handler(const Pistache::Rest::Request &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());
|
||||
@@ -103,6 +109,9 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request,
|
||||
//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());
|
||||
@@ -128,6 +137,9 @@ void PetApi::find_pets_by_tags_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());
|
||||
@@ -145,6 +157,9 @@ void PetApi::get_pet_by_id_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());
|
||||
@@ -165,6 +180,9 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &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());
|
||||
@@ -179,6 +197,9 @@ void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request
|
||||
//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());
|
||||
@@ -193,6 +214,9 @@ void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistach
|
||||
//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