Skip to content

Backend - Refactor duplicated contract-error normalization between contracts.ts and errors.ts #491

@1nonlypiece

Description

@1nonlypiece

Backend - Refactor duplicated contract-error normalization between contracts.ts and errors.ts

Description

src/lib/backend/services/contracts.ts defines a local normalizeContractError that overlaps with normalizeBackendError in src/lib/backend/errors.ts, and the two are mixed inconsistently across functions (some catch blocks use one, others the other). Consolidate into a single normalization path to ensure consistent retryable classification.

Requirements and context

  • Must be secure, tested, and documented
  • Should be efficient and easy to review
  • Centralize chain-error mapping in src/lib/backend/errors.ts
  • Replace mixed usage across all functions in contracts.ts
  • Preserve the retryable flags for 429/503/504/timeout
  • Keep raw RPC details out of client responses

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b chore/consolidate-contract-error-normalization
  • Implement changes
    • Move/merge the normalizer into errors.ts
    • Update all catch blocks in contracts.ts
    • Extend tests in src/lib/backend/errors.test.ts
    • Document the unified mapping in docs/backend-error-codes.md
  • Test and commit
    • Run tests, cover edge cases
    • Include test output and notes

Example commit message

refactor: unify contract-error normalization into errors.ts

Guidelines

  • Minimum 95 percent test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendBackend/API implementationrefactorCode cleanup / restructure

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions