Skip to content

Commit 803bc83

Browse files
committed
chore: changed http status to nestjs enum
1 parent f41cdb9 commit 803bc83

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/filter/all-exception.filter.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Catch,
44
ExceptionFilter,
55
HttpException,
6+
HttpStatus,
67
Logger,
78
} from '@nestjs/common';
89
import { FastifyReply } from 'fastify';
@@ -19,7 +20,7 @@ export class AllExceptionFilter implements ExceptionFilter {
1920
const response = ctx.getResponse<FastifyReply>();
2021

2122
response
22-
.status(exception?.getStatus?.() || 400)
23+
.status(exception?.getStatus?.() || HttpStatus.BAD_REQUEST)
2324
.send(NormalException.UNEXPECTED(exception?.message).toJSON());
2425
}
2526
}

src/filter/normal-exception.filter.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ArgumentsHost, Catch, ExceptionFilter, Logger } from '@nestjs/common';
1+
import {
2+
ArgumentsHost,
3+
Catch,
4+
ExceptionFilter,
5+
HttpStatus,
6+
Logger,
7+
} from '@nestjs/common';
28
import { FastifyReply } from 'fastify';
39
import { NormalException } from '@/exception';
410

@@ -12,6 +18,6 @@ export class NormalExceptionFilter implements ExceptionFilter {
1218
const ctx = host.switchToHttp();
1319
const response = ctx.getResponse<FastifyReply>();
1420

15-
response.status(400).send(exception.toJSON()); // Bad Request
21+
response.status(HttpStatus.BAD_REQUEST).send(exception.toJSON());
1622
}
1723
}

src/filter/validator-exception.filter.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ArgumentsHost, Catch, ExceptionFilter, Logger } from '@nestjs/common';
1+
import {
2+
ArgumentsHost,
3+
Catch,
4+
ExceptionFilter,
5+
HttpStatus,
6+
Logger,
7+
} from '@nestjs/common';
28
import { FastifyReply } from 'fastify';
39
import { NormalException } from '@/exception';
410
import { ValidationError } from 'class-validator';
@@ -17,9 +23,9 @@ export class ValidationExceptionFilter implements ExceptionFilter {
1723
const errorMsg = exception.constraints || exception.children[0].constraints;
1824

1925
response
20-
.status(422)
26+
.status(HttpStatus.UNPROCESSABLE_ENTITY)
2127
.send(
2228
NormalException.VALIDATION_ERROR(Object.values(errorMsg)[0]).toJSON()
23-
); // Unprocessable Entity
29+
);
2430
}
2531
}

0 commit comments

Comments
 (0)