How do I turn off Node.js Express (ejs template engine) errors for production?

后端 未结 2 502
逝去的感伤
逝去的感伤 2021-01-01 02:31

When I\'m on a development server and there is an error, Express sends the traceback as a response.

However, this is not good for production. I don\'t want anyone se

2条回答
  •  时光说笑
    2021-01-01 02:50

    So errors can be coming from express or ejs. In case of:

    1. Express error : Use custom error handling to override the default behaviour. Simply don't send back the error. Read about it on the documentation page. Or you can use already existing middleware such errorhandler like Leonid said to override it.
    2. Template error : Due to jade/ejs etc. Again handle the errors instead of default behaviour which is to send them to client. Use a callback and check for errors. If there is don't display them, instead show an error page.

      res.render(your_template, {}, function(err, html) {
          if(err) {
              res.redirect('/error');
          } else {
              res.send(html);
          }
      });
      

提交回复
热议问题