flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[Backend] Return accurate error codes from topUpStreamHandler instead of blanket 400s

Open blurbeast opened this issue 2 weeks ago • 3 comments

Overview & Background

topUpStreamHandler wraps its entire block — chain call, findUnique, and the raw-SQL increment — in one catch that always returns 400 TOP_UP_FAILED: "Failed to top up stream on chain". A Postgres outage, a Prisma error, or the updatedStream! TypeError is reported to the client as an on-chain failure. Clients cannot distinguish "your transaction reverted" from "our database is down", and monitors keyed on status codes see 400s instead of 5xx. (Compare withdraw.ts:168-170, which correctly maps unexpected errors to 500.)


Technical Specification & Architecture

  1. Narrow the catch in backend/src/controllers/stream.controller.ts:729-732:
    • Soroban/contract errors → 4xx TOP_UP_FAILED.
    • DB/unknown errors → next(error) or a 500 INTERNAL_SERVER_ERROR.
  2. Drop the non-null assertion at :728 (depositedAmount: updatedStream!.depositedAmount) in favor of an explicit null check.

Target Files

  • backend/src/controllers/stream.controller.ts

Acceptance Criteria

  • [ ] DB failures on top-up return 5xx with a generic internal error code.
  • [ ] Contract/simulation failures return 4xx with TOP_UP_FAILED.
  • [ ] No ! non-null assertions remain in the handler.
  • [ ] Unit tests cover both failure classes.

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]