userver: userver/server/handlers/legacy_json_error_builder.hpp Source File
Loading...
Searching...
No Matches
legacy_json_error_builder.hpp
1#pragma once
2
3#include <userver/formats/json/value.hpp>
4#include <userver/http/content_type.hpp>
5
6#include <userver/server/handlers/exceptions.hpp>
7#include <userver/server/http/http_status.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace server::handlers {
12
13/// Legacy JSON error message builder that returns "code" as an integer.
14/// Consider using JsonErrorBuilder instead
16 public:
17 static constexpr bool kIsExternalBodyFormatted = true;
18
19 explicit LegacyJsonErrorBuilder(const CustomHandlerException& ex);
20
21 LegacyJsonErrorBuilder(http::HttpStatus status, std::string internal_message,
22 std::string external_error_body);
23
24 LegacyJsonErrorBuilder(http::HttpStatus status, std::string internal_message,
25 std::string external_error_body,
26 const formats::json::Value& details);
27
28 const std::string& GetInternalMessage() const { return internal_message_; };
29
30 const std::string& GetExternalBody() const { return json_error_body_; }
31
32 static const USERVER_NAMESPACE::http::ContentType& GetContentType() {
33 return USERVER_NAMESPACE::http::content_type::kApplicationJson;
34 }
35
36 private:
37 std::string internal_message_;
38 std::string json_error_body_;
39};
40
41} // namespace server::handlers
42
43USERVER_NAMESPACE_END