Github   Telegram
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
server::handlers::CustomHandlerException Class Reference

Base class for handler exceptions. More...

#include <userver/server/handlers/exceptions.hpp>

+ Inheritance diagram for server::handlers::CustomHandlerException:
+ Collaboration diagram for server::handlers::CustomHandlerException:

Public Types

using HandlerErrorCode = handlers::HandlerErrorCode
 
using ServiceErrorCode = handlers::ServiceErrorCode
 
using InternalMessage = handlers::InternalMessage
 
using ExternalBody = handlers::ExternalBody
 
using ExtraHeaders = handlers::ExtraHeaders
 

Public Member Functions

 CustomHandlerException (impl::CustomHandlerExceptionData data)
 
 CustomHandlerException (ServiceErrorCode service_code, ExternalBody external_body, InternalMessage internal_message, HandlerErrorCode handler_code, ExtraHeaders headers={}, formats::json::Value details={})
 
template<typename MessageBuilder >
 CustomHandlerException (MessageBuilder &&builder, HandlerErrorCode handler_code)
 
HandlerErrorCode GetCode () const
 
const std::string & GetServiceCode () const
 
bool IsExternalErrorBodyFormatted () const
 
const std::string & GetExternalErrorBody () const
 
const formats::json::ValueGetDetails () const
 
const Headers & GetExtraHeaders () const
 

Static Public Attributes

static constexpr HandlerErrorCode kDefaultCode
 

Detailed Description

Base class for handler exceptions.

For consructing the body of an exception a special message builder type could be used. Message builder should satisfy the following requirements:

Example:

class CustomErrorBuilder {
public:
static constexpr bool kIsExternalBodyFormatted = true;
CustomErrorBuilder(std::string status, std::string msg) {
error["code"] = std::move(status);
error["message"] = std::move(msg);
json_error_body = formats::json::ToString(error.ExtractValue());
}
std::string GetExternalBody() const { return json_error_body; }
private:
std::string json_error_body;
};
TEST(CustomErrorBuilder, Sample) {
CustomErrorBuilder{"Bad Request", "Something went wrong"});
EXPECT_EQ(exc.what(), std::string{"Client error"}) << "Log message";
R"({"code":"Bad Request","message":"Something went wrong"})");
EXPECT_EQ(exc.GetExternalErrorBody(), ToString(json));
}

Definition at line 234 of file exceptions.hpp.

Member Typedef Documentation

◆ ExternalBody

Definition at line 240 of file exceptions.hpp.

◆ ExtraHeaders

Definition at line 241 of file exceptions.hpp.

◆ HandlerErrorCode

Definition at line 237 of file exceptions.hpp.

◆ InternalMessage

Definition at line 239 of file exceptions.hpp.

◆ ServiceErrorCode

Definition at line 238 of file exceptions.hpp.

Constructor & Destructor Documentation

◆ CustomHandlerException() [1/3]

server::handlers::CustomHandlerException::CustomHandlerException ( impl::CustomHandlerExceptionData  data)
inline

Definition at line 246 of file exceptions.hpp.

◆ CustomHandlerException() [2/3]

server::handlers::CustomHandlerException::CustomHandlerException ( ServiceErrorCode  service_code,
ExternalBody  external_body,
InternalMessage  internal_message,
HandlerErrorCode  handler_code,
ExtraHeaders  headers = {},
formats::json::Value  details = {} 
)
inline

Definition at line 256 of file exceptions.hpp.

◆ CustomHandlerException() [3/3]

template<typename MessageBuilder >
server::handlers::CustomHandlerException::CustomHandlerException ( MessageBuilder &&  builder,
HandlerErrorCode  handler_code 
)
inline

Definition at line 268 of file exceptions.hpp.

Member Function Documentation

◆ GetCode()

HandlerErrorCode server::handlers::CustomHandlerException::GetCode ( ) const
inline

Definition at line 273 of file exceptions.hpp.

◆ GetDetails()

const formats::json::Value & server::handlers::CustomHandlerException::GetDetails ( ) const
inline

Definition at line 285 of file exceptions.hpp.

◆ GetExternalErrorBody()

const std::string & server::handlers::CustomHandlerException::GetExternalErrorBody ( ) const
inline

Definition at line 281 of file exceptions.hpp.

◆ GetExtraHeaders()

const Headers & server::handlers::CustomHandlerException::GetExtraHeaders ( ) const
inline

Definition at line 287 of file exceptions.hpp.

◆ GetServiceCode()

const std::string & server::handlers::CustomHandlerException::GetServiceCode ( ) const
inline

Definition at line 275 of file exceptions.hpp.

◆ IsExternalErrorBodyFormatted()

bool server::handlers::CustomHandlerException::IsExternalErrorBodyFormatted ( ) const
inline

Definition at line 277 of file exceptions.hpp.

Member Data Documentation

◆ kDefaultCode

constexpr HandlerErrorCode server::handlers::CustomHandlerException::kDefaultCode
staticconstexpr
Initial value:

Definition at line 243 of file exceptions.hpp.


The documentation for this class was generated from the following file: