flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[Backend] Unify the duplicated ApiError classes and conflicting error envelopes

Open blurbeast opened this issue 2 weeks ago • 3 comments

Overview & Background

The backend ships two ApiError classes with swapped constructor signatures — lib/api-error.ts:17-22 is (status, message, code = 'api_error', details?) while types/api-error.ts:14-19 is (statusCode, code, message, details?). A developer constructing one with the other's argument order silently swaps code and message. On top of that there are 4+ ad-hoc response shapes (sendApiError's { error: { code, message } }, simulate.ts's flat { error, code }, stream.controller.ts:135-152's { error, message }, middleware/auth.ts's { error: 'Unauthorized', ... }, webhook.controller.ts:40's { error: error.message }), and middleware/schema-validator.middleware.ts defines a fifth contract (RFC 7807 Problem Details) that is never imported anywhere. error.middleware.ts:50-61 juggles both classes with (err as any) casts to cope.


Technical Specification & Architecture

  1. Keep one ApiError (pick a single constructor signature) and one sendApiError envelope; delete the other class.
  2. Re-map all call sites to the chosen envelope, including webhook.controller.ts and middleware/auth.ts.
  3. Delete or wire up schema-validator.middleware.ts — decide deliberately.

Target Files

  • backend/src/lib/api-error.ts
  • backend/src/types/api-error.ts
  • backend/src/middleware/error.middleware.ts
  • backend/src/middleware/schema-validator.middleware.ts
  • all sendApiError / ad-hoc res.status(...).json({ error ... }) call sites

Acceptance Criteria

  • [ ] Exactly one ApiError class remains; the other is deleted.
  • [ ] All error responses share one documented envelope.
  • [ ] error.middleware.ts no longer uses (err as any) casts for ApiError handling.
  • [ ] schema-validator.middleware.ts is either used or removed.

blurbeast avatar Nov 18 '26 19:11 blurbeast

@eazeeshow has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

Hi maintainer, I can get this issue fixed quickly. Please assign it to me

ℹ️ Repo Maintainers: To accept this application, review their application or assign @eazeeshow to this issue.

eazeeshow avatar Nov 21 '26 12:11 eazeeshow

Congratulations, @eazeeshow! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on November 25, 2026.

🧑‍💻 @eazeeshow: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

🌊 Happy Wave 🌊

drips-wave[bot] avatar Nov 21 '26 12:11 drips-wave[bot]

This issue has been completed by @eazeeshow as part of the Stellar Wave Program's 11th Wave 🥳

😎 @eazeeshow: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

drips-wave[bot] avatar Nov 21 '26 16:11 drips-wave[bot]