Nestjs exception filter wont render handlebars html as response

78 Views Asked by At

I have this controller, which is successfully returning rendered, with handlebars, index.html for root path "/"

 @Controller() 
 export class AppController {
     @Get()
     @Render("index.html")
     root(@Res() res: FastifyReply) {
         return res.view("index.html", { data: "some-data" });
     }
 }

But I want to do the same for all 404's in an exception filter

 @Catch(NotFoundException)
 export class NotFound implements ExceptionFilter {
     catch(exception: NotFoundException, host: ArgumentsHost) {
         const response = host.switchToHttp().getResponse<FastifyReply>();
         return response.view("index.html", { data: "some-data" });
     }
}

But it is not working, it returns an empty response with status 200

0

There are 0 best solutions below