fastify / point-of-view

Template rendering plugin for Fastify
MIT License
338 stars 86 forks source link

How to render view dynamically by http status on ExceptionFilter #358

Open hanadamaru opened 1 year ago

hanadamaru commented 1 year ago

I wish render 500 error page when catch exception on my ExceptionFilter. but display just white page.

catch(exception: Error, host: ArgumentsHost) {
    const ctx                         = host.switchToHttp();
    const response = ctx.getResponse();
    const exceptionStatus             = exception instanceof HttpException ? exception.getStatus() : HttpStatus.INTERNAL_SERVER_ERROR;
    const data                        = exceptionStatus >= HttpStatus.INTERNAL_SERVER_ERROR ? exception['stack'] : undefined;

    this.logger.error(Object.assign({ exceptionStatus: exceptionStatus, msg: exception['message'], stack: data }));

    response.view('errors/500.hbs', {title: '500 ERROR'});
}
Fdawgs commented 1 year ago

Did you manage to solve this @hanadamaru?