src/module/routing/filter/all.exceptions.filter.ts
ExceptionFilter
Methods |
catch | |||||||||
catch(exception: unknown, host: ArgumentsHost)
|
|||||||||
Parameters :
Returns :
void
|
import {ExceptionFilter, Catch, ArgumentsHost, HttpException, HttpStatus, Logger} from '@nestjs/common';
@Catch()
export class AllExceptionsFilter implements ExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const status = exception instanceof HttpException ? exception.getStatus() : HttpStatus.INTERNAL_SERVER_ERROR;
Logger.log('Exception', 'All Exception Filter');
console.log(exception);
response.status(status).send({
code: 1,
message: 'Internal Server Error'
});
}
}