2016-03-18 15:59:03 +00:00
|
|
|
Errors = require "./Errors"
|
|
|
|
logger = require "logger-sharelatex"
|
2016-09-22 14:33:50 +00:00
|
|
|
AuthenticationController = require '../Authentication/AuthenticationController'
|
2016-03-18 15:59:03 +00:00
|
|
|
|
2014-06-20 16:17:24 +00:00
|
|
|
module.exports = ErrorController =
|
|
|
|
notFound: (req, res)->
|
2016-03-18 15:59:03 +00:00
|
|
|
res.status(404)
|
2014-06-20 16:17:24 +00:00
|
|
|
res.render 'general/404',
|
2016-03-18 15:59:03 +00:00
|
|
|
title: "page_not_found"
|
|
|
|
|
|
|
|
serverError: (req, res)->
|
|
|
|
res.status(500)
|
|
|
|
res.render 'general/500',
|
|
|
|
title: "Server Error"
|
2016-09-22 14:33:50 +00:00
|
|
|
|
2016-03-18 15:59:03 +00:00
|
|
|
handleError: (error, req, res, next) ->
|
2016-09-22 14:33:50 +00:00
|
|
|
user = AuthenticationController.getSessionUser(req)
|
2016-03-18 15:59:03 +00:00
|
|
|
if error?.code is 'EBADCSRFTOKEN'
|
2016-09-22 14:33:50 +00:00
|
|
|
logger.warn err: error,url:req.url, method:req.method, user:user, "invalid csrf"
|
2016-03-18 15:59:03 +00:00
|
|
|
res.sendStatus(403)
|
|
|
|
return
|
|
|
|
if error instanceof Errors.NotFoundError
|
2016-03-21 11:55:59 +00:00
|
|
|
logger.warn {err: error, url: req.url}, "not found error"
|
2016-03-18 15:59:03 +00:00
|
|
|
ErrorController.notFound req, res
|
|
|
|
else
|
2016-09-22 14:33:50 +00:00
|
|
|
logger.error err: error, url:req.url, method:req.method, user:user, "error passed to top level next middlewear"
|
|
|
|
ErrorController.serverError req, res
|