Description
src/services/sorobanBilling.ts calls the configured Soroban RPC balance/deduct functions, but RPC failures surface inconsistently to /api/billing/deduct. This backend task maps RPC and network errors to the stable error types in src/errors/index.ts (e.g. PaymentRequiredError, BadGatewayError) so clients get predictable responses.
Requirements and Context
- Categorize Soroban RPC failures (insufficient balance, timeout, contract error, network) into stable error codes.
- Apply categorization in the
/api/billing/deduct handler in src/routes/billing.ts.
- Preserve idempotency behavior keyed by
requestId.
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested Execution
- Fork the repo and create a branch
git checkout -b task/soroban-error-normalization
- Implement changes
src/services/sorobanBilling.ts — classify RPC errors
src/routes/billing.ts — map to error types
src/errors/index.ts — add codes if needed
- Test and commit
npm test -- src/services/sorobanBilling.test.ts
- Cover edge cases
- Include test output and notes in the PR
Example commit message
task: normalize Soroban RPC errors to stable codes
Acceptance Criteria
Guidelines
- Minimum 90% test coverage with Jest
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
src/services/sorobanBilling.tscalls the configured Soroban RPCbalance/deductfunctions, but RPC failures surface inconsistently to/api/billing/deduct. This backend task maps RPC and network errors to the stable error types insrc/errors/index.ts(e.g.PaymentRequiredError,BadGatewayError) so clients get predictable responses.Requirements and Context
/api/billing/deducthandler insrc/routes/billing.ts.requestId.Suggested Execution
src/services/sorobanBilling.ts— classify RPC errorssrc/routes/billing.ts— map to error typessrc/errors/index.ts— add codes if needednpm test -- src/services/sorobanBilling.test.tsExample commit message
Acceptance Criteria
Guidelines