Skip to content

Retrofit lend/swap error handling to named errors + mapSdkError + global onError #474

Description

@its-everdred

PR #465 introduced a centralized error-handling pattern for /borrow routes:

  • Service-level throws use named SDK error classes (e.g. ProviderNotConfiguredError).
  • helpers/errors.ts:mapSdkError maps every known SDK error class to a structured HTTP status (400/403/404/410/422/503).
  • A borrow-scoped app.onError owns all error responses; no per-route try/catch survives.

packages/demo/backend/src/services/lend.ts and packages/demo/backend/src/services/swap.ts still use the old pattern:

  • throw new Error('Wallet not found') / throw new Error('Swap not configured for this wallet') — unrecognized by mapSdkError, surfaces as opaque 500.
  • Inline try { ... } catch (err) { console.error(...); throw err } blocks (lend.ts:34-70, swap.ts:93-113).

Acceptance

  • Replace generic Error(...) throws in services/lend.ts and services/swap.ts with named SDK error classes or new local named classes (e.g. WalletNotFoundError).
  • Extend helpers/errors.ts:mapSdkError mapping table to cover the new classes (and any SDK error classes lend/swap can throw that aren't already mapped).
  • Expand app.ts:77 borrow-scoped onError to also handle /lend, /swap, /wallet/lend, /wallet/swap (or generalize the scoping).
  • Delete per-route try/catch blocks in lend.ts and swap.ts.
  • Add tests asserting each lend/swap service throw maps to the expected HTTP status via app.onError end-to-end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:todoFollow-up task suitable for agent implementation

    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