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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user