userver
C++ Async Framework
Loading...
Searching...
No Matches
http_error.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/server/http/http_error.hpp
4
/// @brief @copybrief server::http::GetHttpStatus
5
6
#
include
<
stdexcept
>
7
#
include
<
string
>
8
9
#
include
<
userver
/
server
/
handlers
/
exceptions
.
hpp
>
10
#
include
<
userver
/
server
/
http
/
http_status
.
hpp
>
11
12
USERVER_NAMESPACE_BEGIN
13
14
namespace
server::http {
15
16
/**
17
* @brief Get http status code mapped to generic handler error code.
18
*
19
* If there is no explicit mapping in the http_error.cpp, will return
20
* HttpStatus::kBadRequest for code values less than
21
* HandlerErrorCode::kServerSideError and will return
22
* HttpStatus::kInternalServerError for the rest of codes.
23
*/
24
HttpStatus
GetHttpStatus
(handlers::
HandlerErrorCode
)
noexcept
;
25
26
/// For server::http::CustomHandlerException, uses the provided HttpStatus.
27
/// For a generic server::handler::CustomHandlerException, converts its
28
/// server::handler::HandlerErrorCode to HttpStatus.
29
HttpStatus
GetHttpStatus
(
30
const
handlers::
CustomHandlerException
& exception)
noexcept
;
31
32
/// @brief An extension of server::handlers::CustomHandlerException that allows
33
/// to specify a custom HttpStatus.
34
///
35
/// For non-HTTP protocols, the status code will be derived from the attached
36
/// server::handlers::HandlerErrorCode.
37
class
CustomHandlerException
:
public
handlers::
CustomHandlerException
{
38
public
:
39
/// @see server::handlers::CustomHandlerException for the description of how
40
/// `args` that can augment error messages.
41
/// @snippet server/handlers/exceptions_test.cpp Sample construction HTTP
42
template
<
typename
... Args>
43
CustomHandlerException
(handlers::
HandlerErrorCode
error_code,
44
HttpStatus
http_status, Args&&... args)
45
: handlers::
CustomHandlerException
(error_code,
46
std::forward<Args>(args)...),
47
http_status_(http_status) {}
48
49
HttpStatus
GetHttpStatus()
const
{
return
http_status_; }
50
51
private
:
52
HttpStatus
http_status_;
53
};
54
55
}
// namespace server::http
56
57
USERVER_NAMESPACE_END
userver
server
http
http_error.hpp
Generated on Wed May 15 2024 22:21:40 for userver by
Doxygen
1.10.0