This is an automated email from the ASF dual-hosted git repository.
dmeden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 4d23ff3f8f RPC: Make sure any internal error gets properly set.
(#11730)
4d23ff3f8f is described below
commit 4d23ff3f8f1e6c182e733570c68c3273d2870ecd
Author: Damian Meden <[email protected]>
AuthorDate: Thu Aug 22 10:20:06 2024 +0200
RPC: Make sure any internal error gets properly set. (#11730)
Thus, the RPC server respond with a proper error response.
This issue was introduced by #10986 when migrated from ts:Errata to
swoc::Errata. This PR makes sure that the right error code gets set
---
include/mgmt/rpc/jsonrpc/Defs.h | 5 +++--
src/mgmt/rpc/jsonrpc/JsonRPCManager.cc | 9 ++++-----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/mgmt/rpc/jsonrpc/Defs.h b/include/mgmt/rpc/jsonrpc/Defs.h
index b99066ec06..b3892595aa 100644
--- a/include/mgmt/rpc/jsonrpc/Defs.h
+++ b/include/mgmt/rpc/jsonrpc/Defs.h
@@ -50,8 +50,9 @@ struct RPCResponseInfo {
RPCResponseInfo(std::string const &id_) : id{id_} {} // Convenient
RPCResponseInfo() = default;
struct Error {
- std::error_code ec; // protocol error track.
- swoc::Errata data; // internal error detail.
+ std::error_code ec; // Protocol error track, @see
rpc::error::RPCErrorCode. !Important: If there is an internal error happening
+ // before we call the rpc handler this should be set,
otherwise the encoder wont render the error properly.
+ swoc::Errata data; // Internal error detail. Optional.
};
std::string id; //!< incoming request id (only used for method calls, empty
means it's a notification as requests with empty id
diff --git a/src/mgmt/rpc/jsonrpc/JsonRPCManager.cc
b/src/mgmt/rpc/jsonrpc/JsonRPCManager.cc
index 80316509bf..742656be43 100644
--- a/src/mgmt/rpc/jsonrpc/JsonRPCManager.cc
+++ b/src/mgmt/rpc/jsonrpc/JsonRPCManager.cc
@@ -62,12 +62,11 @@ swoc::Rv<YAML::Node> g_rpcHandlerResponseData;
bool g_rpcHandlerProcessingCompleted{false};
// --- Helpers
-swoc::Errata
+std::pair<swoc::Errata, error::RPCErrorCode>
check_for_blockers(Context const &ctx, TSRPCHandlerOptions const &options)
{
- if (auto err = ctx.get_auth().is_blocked(options); !err.is_ok()) {
- return
std::move(err.note(swoc::Errata(std::error_code(unsigned(error::RPCErrorCode::Unauthorized),
std::generic_category()),
- ERRATA_ERROR, swoc::Errata::AUTO)));
+ if (auto &&err = ctx.get_auth().is_blocked(options); !err.is_ok()) {
+ return std::make_pair(std::move(err), error::RPCErrorCode::Unauthorized);
}
return {};
}
@@ -112,7 +111,7 @@ JsonRPCManager::Dispatcher::dispatch(Context const &ctx,
specs::RPCRequestInfo c
}
// We have got a valid handler, we will now check if the context holds any
restriction for this handler to be called.
- if (auto errata = check_for_blockers(ctx, handler.get_options());
!errata.is_ok()) {
+ if (auto &&[errata, ec] = check_for_blockers(ctx, handler.get_options());
!errata.is_ok()) {
specs::RPCResponseInfo resp{request.id};
resp.error.ec = ec;
resp.error.data = std::move(errata);