Skip to content

Commit

Permalink
[FOLD] Address review comments:
Browse files Browse the repository at this point in the history
- More error response codes were added based on review comments.
- The new return HTTP return code is enabled by including
  "ripplerpc": "3.0" or higher in the original request.
  • Loading branch information
scottschurr committed Aug 4, 2022
1 parent 96a40b1 commit 98a0ad3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 57 deletions.
76 changes: 38 additions & 38 deletions src/ripple/protocol/impl/ErrorCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,62 +51,62 @@ constexpr static ErrorInfo unorderedErrorInfos[]{
{rpcALREADY_SINGLE_SIG, "alreadySingleSig", "Already single-signed."},
{rpcAMENDMENT_BLOCKED, "amendmentBlocked", "Amendment blocked, need upgrade.", 503},
{rpcEXPIRED_VALIDATOR_LIST, "unlBlocked", "Validator list expired.", 503},
{rpcATX_DEPRECATED, "deprecated", "Use the new API or specify a ledger range."},
{rpcBAD_KEY_TYPE, "badKeyType", "Bad key type."},
{rpcATX_DEPRECATED, "deprecated", "Use the new API or specify a ledger range.", 400},
{rpcBAD_KEY_TYPE, "badKeyType", "Bad key type.", 400},
{rpcBAD_FEATURE, "badFeature", "Feature unknown or invalid.", 500},
{rpcBAD_ISSUER, "badIssuer", "Issuer account malformed."},
{rpcBAD_MARKET, "badMarket", "No such market."},
{rpcBAD_SECRET, "badSecret", "Secret does not match account."},
{rpcBAD_SEED, "badSeed", "Disallowed seed."},
{rpcBAD_ISSUER, "badIssuer", "Issuer account malformed.", 400},
{rpcBAD_MARKET, "badMarket", "No such market.", 404},
{rpcBAD_SECRET, "badSecret", "Secret does not match account.", 403},
{rpcBAD_SEED, "badSeed", "Disallowed seed.", 403},
{rpcBAD_SYNTAX, "badSyntax", "Syntax error.", 400},
{rpcCHANNEL_MALFORMED, "channelMalformed", "Payment channel is malformed."},
{rpcCHANNEL_AMT_MALFORMED, "channelAmtMalformed", "Payment channel amount is malformed."},
{rpcCOMMAND_MISSING, "commandMissing", "Missing command entry."},
{rpcDB_DESERIALIZATION, "dbDeserialization", "Database deserialization error."},
{rpcDST_ACT_MALFORMED, "dstActMalformed", "Destination account is malformed."},
{rpcDST_ACT_MISSING, "dstActMissing", "Destination account not provided."},
{rpcDST_ACT_NOT_FOUND, "dstActNotFound", "Destination account not found."},
{rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency/issuer is malformed."},
{rpcDST_AMT_MISSING, "dstAmtMissing", "Destination amount/currency/issuer is missing."},
{rpcDST_ISR_MALFORMED, "dstIsrMalformed", "Destination issuer is malformed."},
{rpcEXCESSIVE_LGR_RANGE, "excessiveLgrRange", "Ledger range exceeds 1000."},
{rpcCHANNEL_MALFORMED, "channelMalformed", "Payment channel is malformed.", 400},
{rpcCHANNEL_AMT_MALFORMED, "channelAmtMalformed", "Payment channel amount is malformed.", 400},
{rpcCOMMAND_MISSING, "commandMissing", "Missing command entry.", 400},
{rpcDB_DESERIALIZATION, "dbDeserialization", "Database deserialization error.", 502},
{rpcDST_ACT_MALFORMED, "dstActMalformed", "Destination account is malformed.", 400},
{rpcDST_ACT_MISSING, "dstActMissing", "Destination account not provided.", 400},
{rpcDST_ACT_NOT_FOUND, "dstActNotFound", "Destination account not found.", 404},
{rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency/issuer is malformed.", 400},
{rpcDST_AMT_MISSING, "dstAmtMissing", "Destination amount/currency/issuer is missing.", 400},
{rpcDST_ISR_MALFORMED, "dstIsrMalformed", "Destination issuer is malformed.", 400},
{rpcEXCESSIVE_LGR_RANGE, "excessiveLgrRange", "Ledger range exceeds 1000.", 400},
{rpcFORBIDDEN, "forbidden", "Bad credentials.", 403},
{rpcFAILED_TO_FORWARD, "failedToForward", "Failed to forward request to p2p node", 503},
{rpcHIGH_FEE, "highFee", "Current transaction fee exceeds your limit."},
{rpcHIGH_FEE, "highFee", "Current transaction fee exceeds your limit.", 402},
{rpcINTERNAL, "internal", "Internal error.", 500},
{rpcINVALID_LGR_RANGE, "invalidLgrRange", "Ledger range is invalid."},
{rpcINVALID_LGR_RANGE, "invalidLgrRange", "Ledger range is invalid.", 400},
{rpcINVALID_PARAMS, "invalidParams", "Invalid parameters.", 400},
{rpcJSON_RPC, "json_rpc", "JSON-RPC transport error.", 500},
{rpcLGR_IDXS_INVALID, "lgrIdxsInvalid", "Ledger indexes invalid."},
{rpcLGR_IDX_MALFORMED, "lgrIdxMalformed", "Ledger index malformed."},
{rpcLGR_NOT_FOUND, "lgrNotFound", "Ledger not found."},
{rpcLGR_IDXS_INVALID, "lgrIdxsInvalid", "Ledger indexes invalid.", 400},
{rpcLGR_IDX_MALFORMED, "lgrIdxMalformed", "Ledger index malformed.", 400},
{rpcLGR_NOT_FOUND, "lgrNotFound", "Ledger not found.", 404},
{rpcLGR_NOT_VALIDATED, "lgrNotValidated", "Ledger not validated.", 202},
{rpcMASTER_DISABLED, "masterDisabled", "Master key is disabled."},
{rpcMASTER_DISABLED, "masterDisabled", "Master key is disabled.", 403},
{rpcNOT_ENABLED, "notEnabled", "Not enabled in configuration.", 501},
{rpcNOT_IMPL, "notImpl", "Not implemented.", 501},
{rpcNOT_READY, "notReady", "Not ready to handle this request.", 202},
{rpcNOT_READY, "notReady", "Not ready to handle this request.", 503},
{rpcNOT_SUPPORTED, "notSupported", "Operation not supported.", 501},
{rpcNO_CLOSED, "noClosed", "Closed ledger is unavailable.", 503},
{rpcNO_CURRENT, "noCurrent", "Current ledger is unavailable.", 503},
{rpcNOT_SYNCED, "notSynced", "Not synced to the network.", 503},
{rpcNO_EVENTS, "noEvents", "Current transport does not support events."},
{rpcNO_EVENTS, "noEvents", "Current transport does not support events.", 405},
{rpcNO_NETWORK, "noNetwork", "Not synced to the network.", 503},
{rpcNO_PERMISSION, "noPermission", "You don't have permission for this command.", 401},
{rpcNO_PF_REQUEST, "noPathRequest", "No pathfinding request in progress."},
{rpcOBJECT_NOT_FOUND, "objectNotFound", "The requested object was not found."},
{rpcPUBLIC_MALFORMED, "publicMalformed", "Public key is malformed."},
{rpcREPORTING_UNSUPPORTED, "reportingUnsupported", "Requested operation not supported by reporting mode server"},
{rpcSENDMAX_MALFORMED, "sendMaxMalformed", "SendMax amount malformed."},
{rpcSIGNING_MALFORMED, "signingMalformed", "Signing of transaction is malformed."},
{rpcNO_PF_REQUEST, "noPathRequest", "No pathfinding request in progress.", 404},
{rpcOBJECT_NOT_FOUND, "objectNotFound", "The requested object was not found.", 404},
{rpcPUBLIC_MALFORMED, "publicMalformed", "Public key is malformed.", 400},
{rpcREPORTING_UNSUPPORTED, "reportingUnsupported", "Requested operation not supported by reporting mode server", 405},
{rpcSENDMAX_MALFORMED, "sendMaxMalformed", "SendMax amount malformed.", 400},
{rpcSIGNING_MALFORMED, "signingMalformed", "Signing of transaction is malformed.", 400},
{rpcSLOW_DOWN, "slowDown", "You are placing too much load on the server.", 429},
{rpcSRC_ACT_MALFORMED, "srcActMalformed", "Source account is malformed."},
{rpcSRC_ACT_MISSING, "srcActMissing", "Source account not provided."},
{rpcSRC_ACT_NOT_FOUND, "srcActNotFound", "Source account not found."},
{rpcSRC_CUR_MALFORMED, "srcCurMalformed", "Source currency is malformed."},
{rpcSRC_ISR_MALFORMED, "srcIsrMalformed", "Source issuer is malformed."},
{rpcSTREAM_MALFORMED, "malformedStream", "Stream malformed."},
{rpcSRC_ACT_MALFORMED, "srcActMalformed", "Source account is malformed.", 400},
{rpcSRC_ACT_MISSING, "srcActMissing", "Source account not provided.", 400},
{rpcSRC_ACT_NOT_FOUND, "srcActNotFound", "Source account not found.", 404},
{rpcSRC_CUR_MALFORMED, "srcCurMalformed", "Source currency is malformed.", 400},
{rpcSRC_ISR_MALFORMED, "srcIsrMalformed", "Source issuer is malformed.", 400},
{rpcSTREAM_MALFORMED, "malformedStream", "Stream malformed.", 400},
{rpcTOO_BUSY, "tooBusy", "The server is too busy to help you now.", 503},
{rpcTXN_NOT_FOUND, "txnNotFound", "Transaction not found."},
{rpcTXN_NOT_FOUND, "txnNotFound", "Transaction not found.", 404},
{rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown method.", 405}};
// clang-format on

Expand Down
34 changes: 15 additions & 19 deletions src/ripple/rpc/impl/ServerHandlerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,27 +974,23 @@ ServerHandlerImp::processRequest(

// If we're returning an error_code, use that to determine the HTTP status.
int const httpStatus = [&reply]() {
// Handle ripplerpc 1.0.
if (reply.isMember(jss::result) &&
reply[jss::result].isMember(jss::error_code) &&
reply[jss::result][jss::error_code].isInt())
{
int const errCode = reply[jss::result][jss::error_code].asInt();
return RPC::error_code_http_status(
static_cast<error_code_i>(errCode));
}

// Handle ripplerpc 2.0 and greater.
if (reply.isMember(jss::error) &&
reply[jss::error].isMember(jss::error_code) &&
reply[jss::error][jss::error_code].isInt())
// This feature is enabled with ripplerpc version 3.0 and above.
// Before ripplerpc version 3.0 always return 200.
if (reply.isMember(jss::ripplerpc) &&
reply[jss::ripplerpc].isString() &&
reply[jss::ripplerpc].asString() >= "3.0")
{
int const errCode = reply[jss::error][jss::error_code].asInt();
return RPC::error_code_http_status(
static_cast<error_code_i>(errCode));
// If there's an error_code, use that to determine the HTTP Status.
if (reply.isMember(jss::error) &&
reply[jss::error].isMember(jss::error_code) &&
reply[jss::error][jss::error_code].isInt())
{
int const errCode = reply[jss::error][jss::error_code].asInt();
return RPC::error_code_http_status(
static_cast<error_code_i>(errCode));
}
}

// No error code found. Return OK.
// Return OK.
return 200;
}();

Expand Down

0 comments on commit 98a0ad3

Please sign in to comment.