mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-18 02:31:56 +10:00
🚀 release v3.0.0
This commit is contained in:
22
server/src/filters/http-exception.filter.ts
Normal file
22
server/src/filters/http-exception.filter.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from '@nestjs/common';
|
||||
import type { Request, Response } from 'express';
|
||||
import { TypeORMError } from 'typeorm';
|
||||
|
||||
@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 statusCode = exception.getStatus();
|
||||
const message = (exception.getResponse() as TypeORMError).message || exception.message;
|
||||
|
||||
response.status(statusCode).json({
|
||||
statusCode,
|
||||
message,
|
||||
timestamp: new Date().toISOString(),
|
||||
path: request.url,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user