@@ -286,8 +286,7 @@ export const listStreams = async (req: Request, res: Response) => {
286286 : DEFAULT_STREAM_PAGE_SIZE ,
287287 MAX_STREAM_PAGE_SIZE ,
288288 ) ;
289- const parsedOffset =
290- typeof offset === "string" ? Number . parseInt ( offset , 10 ) || 0 : 0 ;
289+ const parsedOffset = typeof offset === 'string' ? Math . max ( 0 , Number . parseInt ( offset , 10 ) || 0 ) : 0 ;
291290
292291 // Validate sort field
293292 const validSortFields = [
@@ -425,9 +424,9 @@ export const getStreamEvents = async (req: Request, res: Response) => {
425424 ) ;
426425
427426 let offset = 0 ;
428- if ( rawOffset && typeof rawOffset === " string" ) {
429- offset = Number . parseInt ( rawOffset , 10 ) || 0 ;
430- } else if ( rawPage && typeof rawPage === " string" && ! cursor ) {
427+ if ( rawOffset && typeof rawOffset === ' string' ) {
428+ offset = Math . max ( 0 , Number . parseInt ( rawOffset , 10 ) || 0 ) ;
429+ } else if ( rawPage && typeof rawPage === ' string' && ! cursor ) {
431430 const page = Number . parseInt ( rawPage , 10 ) || 1 ;
432431 offset = Math . max ( 0 , ( page - 1 ) * limit ) ;
433432 }
@@ -749,9 +748,7 @@ export const topUpStreamHandler = async (req: Request, res: Response) => {
749748 . json ( { streamId, txHash, depositedAmount : newDeposited } ) ;
750749 } catch ( error : any ) {
751750 logger . error ( `[topUp] stream=${ streamId } error:` , error ) ;
752- return res
753- . status ( 500 )
754- . json ( { error : error . message ?? "Internal server error" } ) ;
751+ return res . status ( 400 ) . json ( { error : 'Failed to top up stream on chain' , message : error . message ?? 'Unknown error' } ) ;
755752 }
756753} ;
757754
0 commit comments