Remove exception text from error sending (#1048)

Fixes #1037
This commit is contained in:
Sergey Kuznetsov
2023-12-13 16:30:16 +00:00
committed by GitHub
parent dd35a7cfd2
commit b1dc2775fb
5 changed files with 85 additions and 13 deletions

View File

@@ -23,12 +23,18 @@
#include "util/Assert.h"
#include "web/interface/ConnectionBase.h"
#include <boost/beast/http.hpp>
#include <boost/json.hpp>
#include <boost/beast/http/status.hpp>
#include <boost/json/object.hpp>
#include <boost/json/serialize.hpp>
#include <fmt/core.h>
#include <ripple/protocol/ErrorCodes.h>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <variant>
namespace web::detail {
@@ -127,15 +133,13 @@ public:
}
void
sendJsonParsingError(std::string_view reason) const
sendJsonParsingError() const
{
if (connection_->upgraded) {
connection_->send(
boost::json::serialize(rpc::makeError(rpc::RippledError::rpcBAD_SYNTAX)), boost::beast::http::status::ok
);
connection_->send(boost::json::serialize(rpc::makeError(rpc::RippledError::rpcBAD_SYNTAX)));
} else {
connection_->send(
fmt::format("Unable to parse request: {}", reason), boost::beast::http::status::bad_request
fmt::format("Unable to parse JSON from the request"), boost::beast::http::status::bad_request
);
}
}

View File

@@ -21,6 +21,7 @@
#include "main/Build.h"
#include "rpc/Errors.h"
#include "util/Taggable.h"
#include "util/log/Logger.h"
#include "util/prometheus/Http.h"
#include "web/DOSGuard.h"
@@ -28,13 +29,33 @@
#include "web/interface/Concepts.h"
#include "web/interface/ConnectionBase.h"
#include <boost/asio/error.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/http/error.hpp>
#include <boost/beast/http/field.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/http/status.hpp>
#include <boost/beast/http/string_body.hpp>
#include <boost/beast/http/verb.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/core/ignore_unused.hpp>
#include <boost/json.hpp>
#include <boost/json/array.hpp>
#include <boost/json/parse.hpp>
#include <boost/json/serialize.hpp>
#include <ripple/protocol/ErrorCodes.h>
#include <cstddef>
#include <exception>
#include <functional>
#include <memory>
#include <string>
#include <utility>
namespace web::detail {

View File

@@ -19,17 +19,40 @@
#pragma once
#include "rpc/Errors.h"
#include "rpc/common/Types.h"
#include "util/Taggable.h"
#include "util/log/Logger.h"
#include "web/DOSGuard.h"
#include "web/interface/Concepts.h"
#include "web/interface/ConnectionBase.h"
#include <boost/asio/buffer.hpp>
#include <boost/asio/error.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/core/role.hpp>
#include <boost/beast/http/field.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/http/status.hpp>
#include <boost/beast/http/string_body.hpp>
#include <boost/beast/version.hpp>
#include <boost/beast/websocket/rfc6455.hpp>
#include <boost/beast/websocket/stream_base.hpp>
#include <boost/core/ignore_unused.hpp>
#include <boost/json/array.hpp>
#include <boost/json/parse.hpp>
#include <boost/json/serialize.hpp>
#include <ripple/protocol/ErrorCodes.h>
#include <iostream>
#include <cstddef>
#include <exception>
#include <functional>
#include <memory>
#include <queue>
#include <string>
#include <utility>
namespace web::detail {
@@ -153,7 +176,7 @@ public:
* If the DOSGuard is triggered, the message will be modified to include a warning
*/
void
send(std::string&& msg, http::status = http::status::ok) override
send(std::string&& msg, http::status) override
{
if (!dosGuard_.get().add(clientIp, msg.size())) {
auto jsonResponse = boost::json::parse(msg).as_object();