REFACTOR: Add Auth Validators

This commit is contained in:
Victor Radael
2022-03-28 13:06:03 -03:00
parent 25d99089db
commit 7a95ec537f
24 changed files with 656 additions and 10355 deletions
+7
View File
@@ -0,0 +1,7 @@
import { HttpExceptionFilter } from './http-exception.filter';
describe('HttpExceptionFilter', () => {
it('should be defined', () => {
expect(new HttpExceptionFilter()).toBeDefined();
});
});
+24
View File
@@ -0,0 +1,24 @@
import {
ExceptionFilter,
Catch,
ArgumentsHost,
HttpException,
} from '@nestjs/common';
import { Request, Response } from 'express';
@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter {
catch(exception: HttpException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const request = ctx.getRequest<Request>();
const status = exception.getStatus();
response.status(status).json({
status_code: status,
timestamp: new Date().toISOString(),
path: request.url,
method: request.method,
});
}
}