Skip to content

Commit

Permalink
feat: support validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn0wye committed May 19, 2024
1 parent 1da35cb commit ce3908c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions apps/backend/src/http/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import {
UnprocessableEntityError
} from '@/errors';
import type { FastifyInstance } from 'fastify';
import { ZodError } from 'zod';

export const fastifyErrorHandler: FastifyInstance['errorHandler'] = (
error,
_req,
res
) => {
// if (error instanceof ZodError) {

// reply.status(400).send({
// message: 'Validation error',
// errors: error.flatten().fieldErrors
// });
// }
if (error instanceof ZodError) {
res.status(400).send({
message: 'Validation error',
errors: error.flatten().fieldErrors
});
}

if (error instanceof BadRequestError) {
res.badRequest(error.message);
Expand Down

0 comments on commit ce3908c

Please sign in to comment.