| import { logger } from '@librechat/data-schemas'; |
| import type { Request, Response, NextFunction } from 'express'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function handleJsonParseError( |
| err: Error & { status?: number; body?: unknown }, |
| req: Request, |
| res: Response, |
| next: NextFunction, |
| ): void { |
| if (err instanceof SyntaxError && err.status === 400 && 'body' in err) { |
| logger.warn('[JSON Parse Error] Invalid JSON received', { |
| path: req.path, |
| method: req.method, |
| ip: req.ip, |
| }); |
|
|
| res.status(400).json({ |
| error: 'Invalid JSON format', |
| message: 'The request body contains malformed JSON', |
| }); |
| return; |
| } |
|
|
| next(err); |
| } |
|
|