mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
use error handler
This commit is contained in:
@@ -1,18 +1,12 @@
|
||||
ProjectDetailsHandler = require("./ProjectDetailsHandler")
|
||||
Errors = require("../Errors/Errors")
|
||||
logger = require("logger-sharelatex")
|
||||
|
||||
|
||||
module.exports =
|
||||
|
||||
getProjectDetails : (req, res)->
|
||||
getProjectDetails : (req, res, next)->
|
||||
{project_id} = req.params
|
||||
ProjectDetailsHandler.getDetails project_id, (err, projDetails)->
|
||||
if err? and err instanceof Errors.NotFoundError
|
||||
return res.sendStatus 404
|
||||
else if err?
|
||||
logger.log err:err, project_id:project_id, "something went wrong getting project details"
|
||||
return res.sendStatus 500
|
||||
else
|
||||
res.json(projDetails)
|
||||
return next(err) if err?
|
||||
res.json(projDetails)
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ describe 'Project api controller', ->
|
||||
session:
|
||||
destroy:sinon.stub()
|
||||
@res = {}
|
||||
@next = sinon.stub()
|
||||
@projDetails = {name:"something"}
|
||||
|
||||
|
||||
@@ -34,9 +35,7 @@ describe 'Project api controller', ->
|
||||
@controller.getProjectDetails @req, @res
|
||||
|
||||
|
||||
it "should send a 500 if there is an error", (done)->
|
||||
it "should send a 500 if there is an error", ()->
|
||||
@ProjectDetailsHandler.getDetails.callsArgWith(1, "error")
|
||||
@res.sendStatus = (resCode)=>
|
||||
resCode.should.equal 500
|
||||
done()
|
||||
@controller.getProjectDetails @req, @res
|
||||
@controller.getProjectDetails @req, @res, @next
|
||||
@next.calledWith("error").should.equal true
|
||||
|
||||
Reference in New Issue
Block a user