2016-03-18 11:59:03 -04:00
|
|
|
Errors = require "./Errors"
|
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
|
2014-06-20 12:17:24 -04:00
|
|
|
module.exports = ErrorController =
|
|
|
|
notFound: (req, res)->
|
2016-03-18 11:59:03 -04:00
|
|
|
res.status(404)
|
2014-06-20 12:17:24 -04:00
|
|
|
res.render 'general/404',
|
2016-03-18 11:59:03 -04:00
|
|
|
title: "page_not_found"
|
|
|
|
|
|
|
|
serverError: (req, res)->
|
|
|
|
res.status(500)
|
|
|
|
res.render 'general/500',
|
|
|
|
title: "Server Error"
|
|
|
|
|
|
|
|
handleError: (error, req, res, next) ->
|
|
|
|
if error?.code is 'EBADCSRFTOKEN'
|
|
|
|
logger.log err: error,url:req.url, method:req.method, user:req?.sesson?.user, "invalid csrf"
|
|
|
|
res.sendStatus(403)
|
|
|
|
return
|
|
|
|
logger.error err: error, url:req.url, method:req.method, user:req?.sesson?.user, "error passed to top level next middlewear"
|
|
|
|
if error instanceof Errors.NotFoundError
|
|
|
|
ErrorController.notFound req, res
|
|
|
|
else
|
|
|
|
ErrorController.serverError req, res
|