forked from loafle/openapi-generator-original
[C++][Pistache] Add error handlers overload taking the response object (#19314)
This allows overriders to have full access to the response object and more finely control the error handling behavior. For example, this enables the specification of a proper Content-Type in case of custom format responses (application/json, ...)
This commit is contained in:
parent
e70a9564e0
commit
8af3ff2828
@ -40,6 +40,13 @@ private:
|
||||
{{/operation}}
|
||||
void {{classnameSnakeLowerCase}}_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
@ -47,6 +54,13 @@ private:
|
||||
/// </summary>
|
||||
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
|
@ -33,6 +33,12 @@ void {{classname}}::setupRoutes() {
|
||||
router->addCustomHandler(Routes::bind(&{{classname}}::{{classnameSnakeLowerCase}}_default_handler, this));
|
||||
}
|
||||
|
||||
void {{classname}}::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleParsingException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> {{classname}}::handleParsingException(const std::exception& ex) const noexcept
|
||||
{
|
||||
try {
|
||||
@ -46,6 +52,12 @@ std::pair<Pistache::Http::Code, std::string> {{classname}}::handleParsingExcepti
|
||||
}
|
||||
}
|
||||
|
||||
void {{classname}}::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleOperationException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> {{classname}}::handleOperationException(const std::exception& ex) const noexcept
|
||||
{
|
||||
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||
@ -102,8 +114,7 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
|
||||
{{paramName}} = request.body();
|
||||
{{/isPrimitiveType}}
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -120,8 +131,7 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,12 @@ void PetApi::setupRoutes() {
|
||||
router->addCustomHandler(Routes::bind(&PetApi::pet_api_default_handler, this));
|
||||
}
|
||||
|
||||
void PetApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleParsingException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> PetApi::handleParsingException(const std::exception& ex) const noexcept
|
||||
{
|
||||
try {
|
||||
@ -59,6 +65,12 @@ std::pair<Pistache::Http::Code, std::string> PetApi::handleParsingException(cons
|
||||
}
|
||||
}
|
||||
|
||||
void PetApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleOperationException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> PetApi::handleOperationException(const std::exception& ex) const noexcept
|
||||
{
|
||||
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||
@ -76,8 +88,7 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
|
||||
nlohmann::json::parse(request.body()).get_to(pet);
|
||||
pet.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -87,8 +98,7 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -112,8 +122,7 @@ void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -142,8 +151,7 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request,
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -172,8 +180,7 @@ void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, P
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -194,8 +201,7 @@ void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pista
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -216,8 +222,7 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
|
||||
nlohmann::json::parse(request.body()).get_to(pet);
|
||||
pet.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -227,8 +232,7 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -246,8 +250,7 @@ void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -265,8 +268,7 @@ void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistach
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,13 @@ private:
|
||||
void upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void pet_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
@ -64,6 +71,13 @@ private:
|
||||
/// </summary>
|
||||
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
|
@ -42,6 +42,12 @@ void StoreApi::setupRoutes() {
|
||||
router->addCustomHandler(Routes::bind(&StoreApi::store_api_default_handler, this));
|
||||
}
|
||||
|
||||
void StoreApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleParsingException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> StoreApi::handleParsingException(const std::exception& ex) const noexcept
|
||||
{
|
||||
try {
|
||||
@ -55,6 +61,12 @@ std::pair<Pistache::Http::Code, std::string> StoreApi::handleParsingException(co
|
||||
}
|
||||
}
|
||||
|
||||
void StoreApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleOperationException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> StoreApi::handleOperationException(const std::exception& ex) const noexcept
|
||||
{
|
||||
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||
@ -72,8 +84,7 @@ void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pist
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -92,8 +103,7 @@ void StoreApi::get_inventory_handler(const Pistache::Rest::Request &, Pistache::
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -114,8 +124,7 @@ void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, P
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -136,8 +145,7 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
|
||||
nlohmann::json::parse(request.body()).get_to(order);
|
||||
order.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -147,8 +155,7 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,13 @@ private:
|
||||
void place_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void store_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
@ -59,6 +66,13 @@ private:
|
||||
/// </summary>
|
||||
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
|
@ -46,6 +46,12 @@ void UserApi::setupRoutes() {
|
||||
router->addCustomHandler(Routes::bind(&UserApi::user_api_default_handler, this));
|
||||
}
|
||||
|
||||
void UserApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleParsingException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> UserApi::handleParsingException(const std::exception& ex) const noexcept
|
||||
{
|
||||
try {
|
||||
@ -59,6 +65,12 @@ std::pair<Pistache::Http::Code, std::string> UserApi::handleParsingException(con
|
||||
}
|
||||
}
|
||||
|
||||
void UserApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleOperationException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> UserApi::handleOperationException(const std::exception& ex) const noexcept
|
||||
{
|
||||
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||
@ -76,8 +88,7 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
nlohmann::json::parse(request.body()).get_to(user);
|
||||
user.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -87,8 +98,7 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -109,8 +119,7 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
|
||||
for (const auto& validationParam : user)
|
||||
validationParam.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -120,8 +129,7 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -142,8 +150,7 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request
|
||||
for (const auto& validationParam : user)
|
||||
validationParam.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -153,8 +160,7 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -175,8 +181,7 @@ void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -197,8 +202,7 @@ void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, P
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -235,8 +239,7 @@ void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistach
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -255,8 +258,7 @@ void UserApi::logout_user_handler(const Pistache::Rest::Request &, Pistache::Htt
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -279,8 +281,7 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
nlohmann::json::parse(request.body()).get_to(user);
|
||||
user.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -290,8 +291,7 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,13 @@ private:
|
||||
void update_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void user_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
@ -63,6 +70,13 @@ private:
|
||||
/// </summary>
|
||||
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
|
@ -39,6 +39,12 @@ void StoreApi::setupRoutes() {
|
||||
router->addCustomHandler(Routes::bind(&StoreApi::store_api_default_handler, this));
|
||||
}
|
||||
|
||||
void StoreApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleParsingException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> StoreApi::handleParsingException(const std::exception& ex) const noexcept
|
||||
{
|
||||
try {
|
||||
@ -52,6 +58,12 @@ std::pair<Pistache::Http::Code, std::string> StoreApi::handleParsingException(co
|
||||
}
|
||||
}
|
||||
|
||||
void StoreApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleOperationException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> StoreApi::handleOperationException(const std::exception& ex) const noexcept
|
||||
{
|
||||
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||
@ -67,8 +79,7 @@ void StoreApi::get_nested_object_handler(const Pistache::Rest::Request &, Pistac
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,13 @@ private:
|
||||
void get_nested_object_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void store_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
@ -54,6 +61,13 @@ private:
|
||||
/// </summary>
|
||||
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
|
@ -46,6 +46,12 @@ void PetApi::setupRoutes() {
|
||||
router->addCustomHandler(Routes::bind(&PetApi::pet_api_default_handler, this));
|
||||
}
|
||||
|
||||
void PetApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleParsingException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> PetApi::handleParsingException(const std::exception& ex) const noexcept
|
||||
{
|
||||
try {
|
||||
@ -59,6 +65,12 @@ std::pair<Pistache::Http::Code, std::string> PetApi::handleParsingException(cons
|
||||
}
|
||||
}
|
||||
|
||||
void PetApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleOperationException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> PetApi::handleOperationException(const std::exception& ex) const noexcept
|
||||
{
|
||||
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||
@ -76,8 +88,7 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
|
||||
nlohmann::json::parse(request.body()).get_to(body);
|
||||
body.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -87,8 +98,7 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -112,8 +122,7 @@ void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -142,8 +151,7 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request,
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -172,8 +180,7 @@ void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, P
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -194,8 +201,7 @@ void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pista
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -216,8 +222,7 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
|
||||
nlohmann::json::parse(request.body()).get_to(body);
|
||||
body.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -227,8 +232,7 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -246,8 +250,7 @@ void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -265,8 +268,7 @@ void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistach
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,13 @@ private:
|
||||
void upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void pet_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
@ -64,6 +71,13 @@ private:
|
||||
/// </summary>
|
||||
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
|
@ -42,6 +42,12 @@ void StoreApi::setupRoutes() {
|
||||
router->addCustomHandler(Routes::bind(&StoreApi::store_api_default_handler, this));
|
||||
}
|
||||
|
||||
void StoreApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleParsingException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> StoreApi::handleParsingException(const std::exception& ex) const noexcept
|
||||
{
|
||||
try {
|
||||
@ -55,6 +61,12 @@ std::pair<Pistache::Http::Code, std::string> StoreApi::handleParsingException(co
|
||||
}
|
||||
}
|
||||
|
||||
void StoreApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleOperationException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> StoreApi::handleOperationException(const std::exception& ex) const noexcept
|
||||
{
|
||||
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||
@ -72,8 +84,7 @@ void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pist
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -92,8 +103,7 @@ void StoreApi::get_inventory_handler(const Pistache::Rest::Request &, Pistache::
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -114,8 +124,7 @@ void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, P
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -136,8 +145,7 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
|
||||
nlohmann::json::parse(request.body()).get_to(body);
|
||||
body.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -147,8 +155,7 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,13 @@ private:
|
||||
void place_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void store_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
@ -59,6 +66,13 @@ private:
|
||||
/// </summary>
|
||||
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
|
@ -46,6 +46,12 @@ void UserApi::setupRoutes() {
|
||||
router->addCustomHandler(Routes::bind(&UserApi::user_api_default_handler, this));
|
||||
}
|
||||
|
||||
void UserApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleParsingException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> UserApi::handleParsingException(const std::exception& ex) const noexcept
|
||||
{
|
||||
try {
|
||||
@ -59,6 +65,12 @@ std::pair<Pistache::Http::Code, std::string> UserApi::handleParsingException(con
|
||||
}
|
||||
}
|
||||
|
||||
void UserApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept
|
||||
{
|
||||
std::pair<Pistache::Http::Code, std::string> codeAndError = handleOperationException(ex);
|
||||
response.send(codeAndError.first, codeAndError.second);
|
||||
}
|
||||
|
||||
std::pair<Pistache::Http::Code, std::string> UserApi::handleOperationException(const std::exception& ex) const noexcept
|
||||
{
|
||||
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
|
||||
@ -76,8 +88,7 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
nlohmann::json::parse(request.body()).get_to(body);
|
||||
body.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -87,8 +98,7 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -109,8 +119,7 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
|
||||
for (const auto& validationParam : body)
|
||||
validationParam.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -120,8 +129,7 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -142,8 +150,7 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request
|
||||
for (const auto& validationParam : body)
|
||||
validationParam.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -153,8 +160,7 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -175,8 +181,7 @@ void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -197,8 +202,7 @@ void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, P
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -235,8 +239,7 @@ void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistach
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -255,8 +258,7 @@ void UserApi::logout_user_handler(const Pistache::Rest::Request &, Pistache::Htt
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -279,8 +281,7 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
nlohmann::json::parse(request.body()).get_to(body);
|
||||
body.validate();
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleParsingException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -290,8 +291,7 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
|
||||
response.send(errorInfo.first, errorInfo.second);
|
||||
this->handleOperationException(e, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,13 @@ private:
|
||||
void update_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void user_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
@ -63,6 +70,13 @@ private:
|
||||
/// </summary>
|
||||
virtual std::pair<Pistache::Http::Code, std::string> handleParsingException(const std::exception& ex) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
|
||||
/// </summary>
|
||||
virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept;
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
|
||||
/// May be overridden to return custom error formats. This is called inside a catch block.
|
||||
|
Loading…
x
Reference in New Issue
Block a user