import { ExceptionFilter , Catch , ArgumentsHost , UnauthorizedException , HttpStatus } from '@nestjs/common' ; import i18n from 'i18n' ; import { Request , Response } from 'express' ; @ Catch ( UnauthorizedException ) export class UnauthorizedExceptionFilter implements ExceptionFilter { catch ( exception , host ) { const ctx = host . switchToHttp ( ) ; const response = ctx . getResponse < Response > ( ) ; const request = ctx . getRequest < Request > ( ) ; response . status ( HttpStatus . UNAUTHORIZED ) ; request . flash ( 'error' , i18n . __ ( 'users.form.invalid_credentials' ) ) ; return response . render ( 'auth/sign_in' , { req : request . body } ) ; } }