bug: Unhandled JSON.parse exception causes server crash #5

Open
opened 2026-06-17 15:03:08 +00:00 by abumahid · 0 comments
Owner

Description

In the profile update route, JSON.parse() is called without a try-catch block. Malformed JSON input will throw an uncaught exception, crashing the request handler and potentially the server.

Location

  • File: src/app/modules/profile/profile.route.ts
  • Component: Profile route middleware
  • Lines: 14-17

How to Fix

Wrap the JSON.parse in a try-catch block and pass errors to Express error handler:

(req, res, next) => {
    try {
        req.body = JSON.parse(req?.body?.data);
        next();
    } catch (error) {
        next(error);
    }
}

Acceptance Criteria

  • JSON.parse is wrapped in try-catch
  • Parsing errors are passed to next() middleware
  • Invalid JSON returns proper error response (not 500)
  • Build passes
  • Type check passes

### Description In the profile update route, `JSON.parse()` is called without a try-catch block. Malformed JSON input will throw an uncaught exception, crashing the request handler and potentially the server. ### Location - **File:** `src/app/modules/profile/profile.route.ts` - **Component:** Profile route middleware - **Lines:** 14-17 ### How to Fix Wrap the JSON.parse in a try-catch block and pass errors to Express error handler: ```typescript (req, res, next) => { try { req.body = JSON.parse(req?.body?.data); next(); } catch (error) { next(error); } } ``` ### Acceptance Criteria - [ ] JSON.parse is wrapped in try-catch - [ ] Parsing errors are passed to next() middleware - [ ] Invalid JSON returns proper error response (not 500) - [ ] Build passes - [ ] Type check passes ---
abumahid added the bugCritical labels 2026-06-17 15:03:08 +00:00
abumahid added this to the quicklanch-server project 2026-06-17 15:03:08 +00:00
Sign in to join this conversation.