Skip to content

Fix issues #811, #813, #816#943

Merged
ogazboiz merged 10 commits into
LabsCrypt:mainfrom
Godbrand0:fix-issues-811-813-816
Jul 14, 2026
Merged

Fix issues #811, #813, #816#943
ogazboiz merged 10 commits into
LabsCrypt:mainfrom
Godbrand0:fix-issues-811-813-816

Conversation

@Godbrand0

@Godbrand0 Godbrand0 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Closes #811
Closes #813
Closes #816

Viewed stream.controller.ts:168-194

Here is a detailed comment you can paste directly into the PR description or add as a comment on the pull request:

## Overview of Changes

This PR bundles the fixes for three distinct backend issues to improve error handling, prevent server crashes on invalid inputs, and clean up duplicate route registrations. 

### 1. Fix Negative Pagination Inputs Causing 500 Errors (Closes #811)
**Problem:** 
When the API received negative numbers for the `offset` or `page` query parameters, the values were being passed straight to Prisma's `skip` option. Prisma rejects negative skip values, which caused the endpoints to crash and return a raw `500 Internal Server Error`.

**Solution:**
- Updated the offset parsing logic in `stream.controller.ts` (`listStreams`, `getStreamEvents`) and `user.controller.ts` (`getUserEvents`).
- Implemented a standard clamp using `Math.max(0, ...)` which ensures any negative pagination inputs are clamped to `0`, gracefully preventing the Prisma crash and returning valid paginated data instead.

### 2. Standardize Top-Up On-Chain Error Handling (Closes #813)
**Problem:**
When an on-chain transaction or simulation failed during a stream top-up, the `catch` block in `topUpStreamHandler` was returning a `500 Internal Server Error` containing the raw internal error message. 

**Solution:**
- Modified the error handling in `stream.controller.ts` for the `topUpStreamHandler`.
- It now returns a `400 Bad Request` status with a sanitized and controlled error message (`Failed to top up stream on chain`). 
- This standardizes the behavior so it matches the pattern already used by the `withdraw`, `pause`, and `resume` handlers, ensuring internal stack traces/raw error strings aren't leaked to the client.

### 3. Remove Dead Code for Withdraw Route (Closes #816)
**Problem:**
The `routes/v1/streams/index.ts` file had a redundant and unreachable route registration for `POST /:streamId/withdraw`. Express was already matching the route through `oldStreamRoutes` (mounted just above it), making the second explicit registration dead code.

**Solution:**
- Removed the duplicate `router.post('/:streamId/withdraw', ...)` registration.
- Removed the corresponding unused `withdrawHandler` import to keep the router file clean and less misleading for future development.

@ogazboiz

ogazboiz commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

heads up: main's ci was broken (the Backend CI and Backend Docker Image CI jobs) until the fixes in #969 and #974 just landed, so the red backend/docker checks on this pr are almost certainly stale, they ran against the broken main. please rebase to re-test against the now-green main: git fetch origin && git rebase origin/main && git push --force-with-lease. once it's green i'll review and merge. (if a non-backend check like Frontend CI is still red after the rebase, that part is a real issue worth a look, since frontend ci was passing on main.)

@ogazboiz

ogazboiz commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

nice, this fixes real issues (clamps negative pagination offsets, topUp 500->400, removes the duplicate /withdraw route, and fixes the broken create/page.tsx). the only red is the Docker Image CI infra 'prisma schema' noise, not your code. rebase and it should go green: git fetch origin && git rebase origin/main && git push --force-with-lease. heads up, landing this unblocks the create/page.tsx parse error several other prs are tripping on, so it's a good one to get in early.

@Godbrand0

Copy link
Copy Markdown
Contributor Author

can you merge this issue??

@ogazboiz ogazboiz merged commit 5bf613d into LabsCrypt:main Jul 14, 2026
3 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants