File

src/module/routing/filter/all.exceptions.filter.ts

Implements

ExceptionFilter

Index

Methods

Methods

catch
catch(exception: unknown, host: ArgumentsHost)
Parameters :
Name Type Optional
exception unknown No
host ArgumentsHost No
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'
		});
	}
}

result-matching ""

    No results matching ""