Make it an error when we get no data from joinProject

This commit is contained in:
Shane Kilkelly 2019-10-11 09:57:16 +01:00
parent df6cd4a054
commit 06aa578bdc
2 changed files with 15 additions and 1 deletions

View file

@ -24,7 +24,11 @@ module.exports = WebApiManager =
}, (error, response, data) ->
return callback(error) if error?
if 200 <= response.statusCode < 300
callback null, data?.project, data?.privilegeLevel, data?.isRestrictedUser
if !data? || !data?.project?
err = new Error('no data returned from joinProject request')
logger.error {err, project_id, user_id}, "error accessing web api"
return callback(err)
callback null, data.project, data.privilegeLevel, data.isRestrictedUser
else if response.statusCode == 429
logger.log(project_id, user_id, "rate-limit hit when joining project")
callback(new CodedError("rate-limit hit when joining project", "TooManyRequests"))

View file

@ -63,6 +63,16 @@ describe 'WebApiManager', ->
.calledWith(new Error("non-success code from web: 500"))
.should.equal true
describe "with no data from web", ->
beforeEach ->
@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 200}, null)
@WebApiManager.joinProject @project_id, @user_id, @callback
it "should call the callback with an error", ->
@callback
.calledWith(new Error("no data returned from joinProject request"))
.should.equal true
describe "when the project is over its rate limit", ->
beforeEach ->
@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 429}, null)