File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import UploadRouter from './router/upload.js';
3434import { ajvFilePlugin } from '@fastify/multipart' ;
3535import { UploadSchema } from './schema/Upload.js' ;
3636import { NoteHierarchySchema } from './schema/NoteHierarchy.js' ;
37+ import { StatusCodes } from 'http-status-codes' ;
3738
3839const appServerLogger = getLogger ( 'appServer' ) ;
3940
@@ -372,6 +373,21 @@ export default class HttpApi implements Api {
372373
373374 return ;
374375 }
376+ /**
377+ * JSON parse errors (invalid request body)
378+ */
379+ if ( error instanceof SyntaxError && error . message . includes ( 'JSON' ) ) {
380+ this . log . warn ( { reqId : request . id } , 'Invalid JSON in request body' ) ;
381+
382+ return reply
383+ . code ( StatusCodes . BAD_REQUEST )
384+ . type ( 'application/json' )
385+ . send ( {
386+ message : 'Invalid JSON in request body' ,
387+ error : 'Bad Request' ,
388+ statusCode : StatusCodes . BAD_REQUEST ,
389+ } ) ;
390+ }
375391 /**
376392 * If error is not a domain error, we route it to the default error handler
377393 */
You can’t perform that action at this time.
0 commit comments