userver: userver/server/http/http_error.hpp Source File
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
8#include <userver/server/handlers/exceptions.hpp>
9#include <userver/server/http/http_status.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace server::http {
14
15/**
16 * @brief Get http status code mapped to generic handler error code.
17 *
18 * If there is no explicit mapping in the http_error.cpp, will return
19 * HttpStatus::kBadRequest for code values less than
20 * HandlerErrorCode::kServerSideError and will return
21 * HttpStatus::kInternalServerError for the rest of codes.
22 */
24
25/// For server::http::CustomHandlerException, uses the provided HttpStatus.
26/// For a generic server::handler::CustomHandlerException, converts its
27/// server::handler::HandlerErrorCode to HttpStatus.
29
30/// @brief An extension of server::handlers::CustomHandlerException that allows
31/// to specify a custom HttpStatus.
32///
33/// For non-HTTP protocols, the status code will be derived from the attached
34/// server::handlers::HandlerErrorCode.
36public:
37 /// @see server::handlers::CustomHandlerException for the description of how
38 /// `args` that can augment error messages.
39 /// @snippet core/src/server/handlers/exceptions_test.cpp Sample construction HTTP
40 template <typename... Args>
41 CustomHandlerException(handlers::HandlerErrorCode error_code, HttpStatus http_status, Args&&... args)
42 : handlers::CustomHandlerException(error_code, std::forward<Args>(args)...),
43 http_status_(http_status)
44 {}
45
46 HttpStatus GetHttpStatus() const { return http_status_; }
47
48private:
49 HttpStatus http_status_;
50};
51
52} // namespace server::http
53
54USERVER_NAMESPACE_END