Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ErrorHandling.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "rpc/Errors.hpp"
23#include "web/ng/Request.hpp"
24#include "web/ng/Response.hpp"
25
26#include <boost/beast/http/status.hpp>
27#include <boost/json/object.hpp>
28#include <boost/json/serialize.hpp>
29#include <fmt/core.h>
30#include <xrpl/protocol/ErrorCodes.h>
31#include <xrpl/protocol/jss.h>
32
33#include <functional>
34#include <optional>
35
36namespace web::ng::impl {
37
42 std::reference_wrapper<Request const> rawRequest_;
43 std::optional<boost::json::object> request_;
44
45public:
52 ErrorHelper(Request const& rawRequest, std::optional<boost::json::object> request = std::nullopt);
53
60 [[nodiscard]] Response
61 makeError(rpc::Status const& err) const;
62
68 [[nodiscard]] Response
69 makeInternalError() const;
70
76 [[nodiscard]] Response
77 makeNotReadyError() const;
78
84 [[nodiscard]] Response
85 makeTooBusyError() const;
86
92 [[nodiscard]] Response
94
101 [[nodiscard]] boost::json::object
102 composeError(rpc::Status const& error) const;
103
110 [[nodiscard]] boost::json::object
111 composeError(rpc::RippledError error) const;
112};
113
114} // namespace web::ng::impl
Represents an HTTP or WebSocket request.
Definition Request.hpp:37
Represents an HTTP or Websocket response.
Definition Response.hpp:40
A helper that attempts to match rippled reporting mode HTTP errors as close as possible.
Definition ErrorHandling.hpp:41
Response makeTooBusyError() const
Make a response for when the server is too busy.
Definition ErrorHandling.cpp:133
boost::json::object composeError(rpc::Status const &error) const
Definition ErrorHandling.cpp:153
Response makeJsonParsingError() const
Make a response when json parsing fails.
Definition ErrorHandling.cpp:143
Response makeError(rpc::Status const &err) const
Make an error response from a status.
Definition ErrorHandling.cpp:77
Response makeNotReadyError() const
Make a response for when the server is not ready.
Definition ErrorHandling.cpp:127
Response makeInternalError() const
Make an internal error response.
Definition ErrorHandling.cpp:121
ErrorHelper(Request const &rawRequest, std::optional< boost::json::object > request=std::nullopt)
Construct a new Error Helper object.
Definition ErrorHandling.cpp:71
ripple::error_code_i RippledError
Clio uses compatible Rippled error codes for most RPC errors.
Definition Errors.hpp:71
A status returned from any RPC handler.
Definition Errors.hpp:82