Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LoadWarning.hpp
1#pragma once
2
3#include "rpc/Errors.hpp"
4
5#include <boost/json/array.hpp>
6#include <boost/json/object.hpp>
7#include <boost/json/parse.hpp>
8#include <boost/system/error_code.hpp>
9#include <rpcspec/backends/BoostJson.hpp>
10
11#include <optional>
12#include <string_view>
13
14namespace web {
15
32inline std::optional<boost::json::object>
33withLoadWarning(std::string_view message)
34{
35 boost::system::error_code ec;
36 auto const parsed = boost::json::parse(message, ec);
37 if (ec.failed() or not parsed.is_object())
38 return std::nullopt;
39
40 auto jsonResponse = parsed.as_object();
41 jsonResponse["warning"] = "load";
42
43 if (jsonResponse.contains("warnings") and jsonResponse["warnings"].is_array()) {
44 jsonResponse["warnings"].as_array().push_back(
45 rpc::makeWarning(rpc::WarningCode::WarnRpcRateLimit)
46 );
47 } else {
48 jsonResponse["warnings"] =
49 boost::json::array{rpc::makeWarning(rpc::WarningCode::WarnRpcRateLimit)};
50 }
51
52 return jsonResponse;
53}
54
55} // namespace web
This namespace implements the web server and related components.
Definition Types.hpp:23
std::optional< boost::json::object > withLoadWarning(std::string_view message)
Parse a serialized response body and attach the DOSGuard "load" warning to it.
Definition LoadWarning.hpp:33