AOSSIE-Org / AOSSIE-Org/Resonate-Backend

[BUG]: Improve request validation and JSON parsing across backend functions

Đang mở
#167 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
JavaScript
Star
43
Fork
120
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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

- [x] I have joined the [Discord server](https://discord.gg/hjUhu33uAn) and will post updates there
- [x] I have searched existing issues to avoid duplicates

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.