fix: map ledger errors to correct HTTP status codes (EN-1203)#108
fix: map ledger errors to correct HTTP status codes (EN-1203)#108flemzord wants to merge 1 commit into
Conversation
Several error paths returned 500 (or leaked internals) where a 4xx was correct, and the insufficient-funds mapping was dead code. - H1: DefaultLedger.CreateTransaction now translates the SDK *sdkerrors.V2ErrorResponse (INSUFFICIENT_FUND) to ErrInsufficientFundError. The previous switch on *sdkerrors.WalletsErrorResponse never matched in production (the SDK never returns that type), so insufficient funds 500'd. - M2: GetWallet/GetBalance/GetHold/ConfirmHold/VoidHold now map account not-found to the proper domain error (404). GetHold/VoidHold also verify the account is actually a hold. - M3: internalError no longer echoes err.Error() to the client (it leaked ledger URLs, account addresses and SDK internals); a generic message is returned and the full error is still logged. - M4: a debit whose resolved balances are all expired returns INSUFFICIENT_FUND instead of building an empty-source script (ledger 500). - M6: a malformed pagination cursor (ledger VALIDATION error) now returns 400 instead of 500. Updates the insufficient-funds test to use the real domain error and adds regression tests for hold 404 and the all-expired-balance debit.
|
Warning Review limit reached
More reviews will be available in 43 minutes and 19 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (12)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem (High + Medium — H1, M2, M3, M4, M6)
Several error paths returned
500(or leaked internals) where a4xxwas correct, and the insufficient-funds mapping was effectively dead code.Manager.CreateTransactiononly mapped insufficient funds when the error was*sdkerrors.WalletsErrorResponse, but the ledger SDK'sV2.CreateTransactionalways returns*sdkerrors.V2ErrorResponse. The branch never matched in production, so a debit/confirm with insufficient funds returned 500 instead of 400 INSUFFICIENT_FUND. The unit test passed only because the mock injected the wrong (fake) type.GetWallet,GetBalance,GetHold,ConfirmHold,VoidHoldreturned 500 (or a phantom 200) for missing entities instead of 404.internalErrorechoederr.Error()to the client, leaking ledger URLs, account addresses and SDK internals.source = { }, an invalid script the ledger rejects as a 500.Fix
ErrInsufficientFundErrorinDefaultLedger.CreateTransaction(same pattern already used byGetAccountfor not-found); drop the dead switch inManager.CreateTransaction.ErrAccountNotFoundto the proper domain errors in the read/confirm/void paths; verifyIsHoldinGetHold/VoidHold; handlers answer 404.internalErrorreturns a generic message and logs the full error server-side.INSUFFICIENT_FUND.ErrValidationsentinel:ListAccounts/ListTransactionsmap the ledger VALIDATION error so list handlers answer 400.Tests
TestHoldsGetNotFound,TestHoldsGetWrongAccountType, and a debit "with only expired balance" case → 400.Note
Touches the four list handlers, which are also edited by #107 (api-hardening, pageSize). Expect a trivial rebase on whichever merges second.
From the in-depth repository review.