Sylvain Joubert 8af3ff2828
[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, ...)
2024-08-14 14:31:55 +08:00

92 lines
3.1 KiB
C++

/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* StoreApi.h
*
*
*/
#ifndef StoreApi_H_
#define StoreApi_H_
#include "ApiBase.h"
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <optional>
#include <utility>
#include "OuterType.h"
namespace org::openapitools::server::api
{
class StoreApi : public ApiBase {
public:
explicit StoreApi(const std::shared_ptr<Pistache::Rest::Router>& rtr);
~StoreApi() override = default;
void init() override;
static const std::string base;
private:
void setupRoutes();
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.
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
/// </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.
/// Important: When overriding, do not call `throw ex;`, but instead use `throw;`.
/// </summary>
virtual std::pair<Pistache::Http::Code, std::string> handleOperationException(const std::exception& ex) const noexcept;
/// <summary>
///
/// </summary>
/// <remarks>
///
/// </remarks>
virtual void get_nested_object(Pistache::Http::ResponseWriter &response) = 0;
};
} // namespace org::openapitools::server::api
#endif /* StoreApi_H_ */