Skip to content

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

Open
Godbrand0 wants to merge 8 commits into
LabsCrypt:mainfrom
Godbrand0:fix-issues-811-813-816
Open

Fix issues #811, #813, #816#943
Godbrand0 wants to merge 8 commits into
LabsCrypt:mainfrom
Godbrand0:fix-issues-811-813-816

Conversation

@Godbrand0

@Godbrand0 Godbrand0 commented Jun 29, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant