[Backend] Unify the duplicated ApiError classes and conflicting error envelopes
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
- Keep one
ApiError(pick a single constructor signature) and onesendApiErrorenvelope; delete the other class. - Re-map all call sites to the chosen envelope, including
webhook.controller.tsandmiddleware/auth.ts. - Delete or wire up
schema-validator.middleware.ts— decide deliberately.
Target Files
backend/src/lib/api-error.tsbackend/src/types/api-error.tsbackend/src/middleware/error.middleware.tsbackend/src/middleware/schema-validator.middleware.ts- all
sendApiError/ ad-hocres.status(...).json({ error ... })call sites
Acceptance Criteria
- [ ] Exactly one
ApiErrorclass remains; the other is deleted. - [ ] All error responses share one documented envelope.
- [ ]
error.middleware.tsno longer uses(err as any)casts for ApiError handling. - [ ]
schema-validator.middleware.tsis either used or removed.
@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.
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 🌊
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.