From 0b81a8c783943f99fe29657a7d1edc46a9e77ba5 Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Thu, 3 Oct 2024 14:25:49 +0200 Subject: [PATCH] Adjust error code on portal_*TraceRecursiveFindContent (#2687) --- fluffy/rpc/rpc_portal_api.nim | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fluffy/rpc/rpc_portal_api.nim b/fluffy/rpc/rpc_portal_api.nim index 923da9075..147fe77ed 100644 --- a/fluffy/rpc/rpc_portal_api.nim +++ b/fluffy/rpc/rpc_portal_api.nim @@ -24,6 +24,10 @@ export rpcserver, tables # Portal Network JSON-RPC impelentation as per specification: # https://github.com/ethereum/portal-network-specs/tree/master/jsonrpc +const + ContentNotFoundError = (code: -39001, msg: "Content not found") + ContentNotFoundErrorWithTrace = (code: -39002, msg: "Content not found") + type ContentInfo = object content: string utpTransfer: bool @@ -189,7 +193,9 @@ proc installPortalApiHandlers*( raise (ref errors.InvalidRequest)(code: -32602, msg: "Invalid content key") contentResult = (await p.contentLookup(key, contentId)).valueOr: - raise (ref ApplicationError)(code: -39001, msg: "Content not found") + raise (ref ApplicationError)( + code: ContentNotFoundError.code, msg: ContentNotFoundError.msg + ) return ContentInfo( content: contentResult.content.to0xHex(), utpTransfer: contentResult.utpTransfer @@ -211,7 +217,11 @@ proc installPortalApiHandlers*( return res else: let data = Opt.some(JrpcConv.encode(res.trace).JsonString) - raise (ref ApplicationError)(code: -39001, msg: "Content not found", data: data) + raise (ref ApplicationError)( + code: ContentNotFoundErrorWithTrace.code, + msg: ContentNotFoundErrorWithTrace.msg, + data: data, + ) rpcServer.rpc("portal_" & network & "Store") do( contentKey: string, contentValue: string @@ -257,7 +267,9 @@ proc installPortalApiHandlers*( raise (ref errors.InvalidRequest)(code: -32602, msg: "Invalid content key") contentResult = p.dbGet(key, contentId).valueOr: - raise (ref ApplicationError)(code: -39001, msg: "Content not found") + raise (ref ApplicationError)( + code: ContentNotFoundError.code, msg: ContentNotFoundError.msg + ) return contentResult.to0xHex()