mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-25 06:31:52 +00:00
Merge pull request #511 from sharelatex/bg-handle-web-api-errors
use a separate error handler for api router errors
This commit is contained in:
commit
b277ee3254
2 changed files with 10 additions and 1 deletions
|
@ -32,3 +32,11 @@ module.exports = ErrorController =
|
||||||
else
|
else
|
||||||
logger.error err: error, url:req.url, method:req.method, user:user, "error passed to top level next middlewear"
|
logger.error err: error, url:req.url, method:req.method, user:user, "error passed to top level next middlewear"
|
||||||
ErrorController.serverError req, res
|
ErrorController.serverError req, res
|
||||||
|
|
||||||
|
handleApiError: (error, req, res, next) ->
|
||||||
|
if error instanceof Errors.NotFoundError
|
||||||
|
logger.warn {err: error, url: req.url}, "not found error"
|
||||||
|
res.sendStatus(404)
|
||||||
|
else
|
||||||
|
logger.error err: error, url:req.url, method:req.method, user:user, "error passed to top level next middlewear"
|
||||||
|
res.sendStatus(500)
|
||||||
|
|
|
@ -164,11 +164,12 @@ server = require('http').createServer(app)
|
||||||
# process api routes first, if nothing matched fall though and use
|
# process api routes first, if nothing matched fall though and use
|
||||||
# web middlewear + routes
|
# web middlewear + routes
|
||||||
app.use(apiRouter)
|
app.use(apiRouter)
|
||||||
|
app.use(ErrorController.handleApiError)
|
||||||
app.use(webRouter)
|
app.use(webRouter)
|
||||||
|
app.use(ErrorController.handleError)
|
||||||
|
|
||||||
router = new Router(webRouter, apiRouter)
|
router = new Router(webRouter, apiRouter)
|
||||||
|
|
||||||
app.use ErrorController.handleError
|
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
app: app
|
app: app
|
||||||
|
|
Loading…
Reference in a new issue