ErrorController.coffee 929 B

123456789101112131415161718192021222324252627
  1. Errors = require "./Errors"
  2. logger = require "logger-sharelatex"
  3. AuthenticationController = require '../Authentication/AuthenticationController'
  4. module.exports = ErrorController =
  5. notFound: (req, res)->
  6. res.status(404)
  7. res.render 'general/404',
  8. title: "page_not_found"
  9. serverError: (req, res)->
  10. res.status(500)
  11. res.render 'general/500',
  12. title: "Server Error"
  13. handleError: (error, req, res, next) ->
  14. user = AuthenticationController.getSessionUser(req)
  15. if error?.code is 'EBADCSRFTOKEN'
  16. logger.warn err: error,url:req.url, method:req.method, user:user, "invalid csrf"
  17. res.sendStatus(403)
  18. return
  19. if error instanceof Errors.NotFoundError
  20. logger.warn {err: error, url: req.url}, "not found error"
  21. ErrorController.notFound req, res
  22. else
  23. logger.error err: error, url:req.url, method:req.method, user:user, "error passed to top level next middlewear"
  24. ErrorController.serverError req, res