Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/presentation/http/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import UploadRouter from './router/upload.js';
import { ajvFilePlugin } from '@fastify/multipart';
import { UploadSchema } from './schema/Upload.js';
import { NoteHierarchySchema } from './schema/NoteHierarchy.js';
import { StatusCodes } from 'http-status-codes';

const appServerLogger = getLogger('appServer');

Expand Down Expand Up @@ -372,6 +373,21 @@ export default class HttpApi implements Api {

return;
}
/**
* JSON parse errors (invalid request body)
*/
if (error instanceof SyntaxError && error.message.includes('JSON')) {
Comment thread
7eliassen marked this conversation as resolved.
Outdated
this.log.warn({ reqId: request.id }, 'Invalid JSON in request body');

return reply
.code(StatusCodes.BAD_REQUEST)
.type('application/json')
.send({
message: 'Invalid JSON in request body',
error: 'Bad Request',
statusCode: StatusCodes.BAD_REQUEST,
Comment thread
7eliassen marked this conversation as resolved.
Outdated
});
Comment thread
7eliassen marked this conversation as resolved.
}
/**
* If error is not a domain error, we route it to the default error handler
*/
Expand Down
Loading