Skip to content

Normalize Soroban RPC errors in sorobanBilling.ts into stable API error codes for /api/billing/deduct #319

@greatest0fallt1me

Description

@greatest0fallt1me

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

  1. Fork the repo and create a branch
    git checkout -b task/soroban-error-normalization
  2. 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
  3. 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

  • Insufficient balance maps to 402, timeout to 504, contract/network to 502
  • Error codes are stable and documented
  • Idempotent deduct behavior is preserved

Guidelines

  • Minimum 90% test coverage with Jest
  • Clear documentation and inline comments
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programapiAPI endpoint/contract workbackendBackend service workenhancementNew feature or improvement

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions