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
Backend - Refactor duplicated contract-error normalization between contracts.ts and errors.ts
Description
src/lib/backend/services/contracts.tsdefines a localnormalizeContractErrorthat overlaps withnormalizeBackendErrorinsrc/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
src/lib/backend/errors.tscontracts.tsSuggested execution
git checkout -b chore/consolidate-contract-error-normalizationerrors.tscontracts.tssrc/lib/backend/errors.test.tsdocs/backend-error-codes.mdExample commit message
refactor: unify contract-error normalization into errors.tsGuidelines