Separate exception types (#2930)

This commit is contained in:
sunn
2019-05-18 11:57:23 +02:00
committed by GitHub
parent f550553e3f
commit e85e1f112a
28 changed files with 195 additions and 111 deletions

View File

@@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -54,10 +54,14 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
try {
nlohmann::json::parse(request.body()).get_to(body);
this->add_pet(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
@@ -70,10 +74,14 @@ void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache
try {
this->delete_pet(petId, apiKey, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
@@ -91,10 +99,14 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request,
try {
this->find_pets_by_status(status, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
@@ -112,10 +124,14 @@ void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, P
try {
this->find_pets_by_tags(tags, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
@@ -125,10 +141,14 @@ void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pista
try {
this->get_pet_by_id(petId, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
@@ -141,30 +161,42 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
try {
nlohmann::json::parse(request.body()).get_to(body);
this->update_pet(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
this->update_pet_with_form(request, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
this->upload_file(request, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::runtime_error &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}