mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #466 from sharelatex/bg-prevent-exception-on-nonexistent-project
fix unhandled exception in ProjectDetailsHandler
This commit is contained in:
commit
e8039c3204
4 changed files with 16 additions and 9 deletions
|
@ -4,11 +4,9 @@ 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?
|
||||
logger.log err:err, project_id:project_id, "something went wrong getting project details"
|
||||
return res.sendStatus 500
|
||||
return next(err) if err?
|
||||
res.json(projDetails)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ logger = require("logger-sharelatex")
|
|||
tpdsUpdateSender = require '../ThirdPartyDataStore/TpdsUpdateSender'
|
||||
_ = require("underscore")
|
||||
PublicAccessLevels = require("../Authorization/PublicAccessLevels")
|
||||
Errors = require("../Errors/Errors")
|
||||
|
||||
module.exports =
|
||||
|
||||
|
@ -13,6 +14,7 @@ module.exports =
|
|||
if err?
|
||||
logger.err err:err, project_id:project_id, "error getting project"
|
||||
return callback(err)
|
||||
return callback(new Errors.NotFoundError("project not found")) if !project?
|
||||
UserGetter.getUser project.owner_ref, (err, user) ->
|
||||
return callback(err) if err?
|
||||
details =
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
should = require('chai').should()
|
||||
modulePath = "../../../../app/js/Features/Project/ProjectDetailsHandler"
|
||||
Errors = require "../../../../app/js/Features/Errors/Errors"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
sinon = require('sinon')
|
||||
assert = require("chai").assert
|
||||
|
@ -48,6 +49,13 @@ describe 'ProjectDetailsHandler', ->
|
|||
assert.equal(details.something, undefined)
|
||||
done()
|
||||
|
||||
it "should return an error for a non-existent project", (done)->
|
||||
@ProjectGetter.getProject.callsArg(2, null, null)
|
||||
err = new Errors.NotFoundError("project not found")
|
||||
@handler.getDetails "0123456789012345678901234", (error, details) =>
|
||||
err.should.eql error
|
||||
done()
|
||||
|
||||
it "should return the error", (done)->
|
||||
error = "some error"
|
||||
@ProjectGetter.getProject.callsArgWith(2, error)
|
||||
|
|
Loading…
Reference in a new issue