Bug Description
Problem
Currently, multiple backend functions directly use JSON.parse(req.body) and perform validation using throwIfMissing. This approach has a few issues:
- Repeated parsing of request body across functions
- No centralized handling for invalid JSON (can cause runtime crashes)
- Validation utility previously treated falsy values (
0, false, "") as missing
- Inconsistent error responses across different functions
Proposed Solution
- Enhance the existing
throwIfMissing utility to correctly handle falsy values by only rejecting undefined and null
- Introduce a reusable
parseBody utility for safe JSON parsing
- Refactor selected functions (e.g.,
create-room, join-room) to:
- Use
parseBody for request parsing
- Use improved validation
- Standardize API responses (
success, message, data)
Benefits
- Prevents crashes due to invalid JSON input
- Improves consistency across backend APIs
- Enhances maintainability and readability
- Moves towards production-grade request handling
Scope
- Update
utils.js
- Refactor 2–3 functions to adopt new utilities
Steps to Reproduce
No response
Logs and Screenshots
No response
Environment Details
No response
Impact
Critical - Application is unusable
Code of Conduct
Bug Description
Problem
Currently, multiple backend functions directly use
JSON.parse(req.body)and perform validation usingthrowIfMissing. This approach has a few issues:0,false,"") as missingProposed Solution
throwIfMissingutility to correctly handle falsy values by only rejectingundefinedandnullparseBodyutility for safe JSON parsingcreate-room,join-room) to:parseBodyfor request parsingsuccess,message,data)Benefits
Scope
utils.jsSteps to Reproduce
No response
Logs and Screenshots
No response
Environment Details
No response
Impact
Critical - Application is unusable
Code of Conduct