userver: userver/http/parse_status_code.hpp Source File
Loading...
Searching...
No Matches
parse_status_code.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <fmt/format.h>
8
12
13USERVER_NAMESPACE_BEGIN
14
15namespace http {
16
18template <formats::common::IsFormatValue Value>
19StatusCode Parse(const Value& value, formats::parse::To<StatusCode>) {
20 using IntType = std::underlying_type_t<StatusCode>;
21 constexpr IntType kMinCode = 100;
22 constexpr IntType kMaxCode = 599;
23
24 const auto integer = value.template As<IntType>();
25 if (integer < kMinCode || integer > kMaxCode) {
26 throw typename Value::Exception(fmt::format(
27 "StatusCode value {} out of [{}..{}] range at '{}'",
28 integer,
29 kMinCode,
30 kMaxCode,
31 value.GetPath()
32 ));
33 }
34
35 return StatusCode{integer};
36}
37
38} // namespace http
39
40USERVER_NAMESPACE_END