Merge pull request #302 from sharelatex/msw-history-failure

Bail out if history API request fails
This commit is contained in:
Alasdair Smith 2018-02-06 10:35:57 +00:00 committed by GitHub
commit e3811d33e9
2 changed files with 26 additions and 4 deletions

View file

@ -46,9 +46,14 @@ module.exports = HistoryController =
"X-User-Id": user_id
}, (error, response, body) ->
return next(error) if error?
HistoryManager.injectUserDetails body, (error, data) ->
return next(error) if error?
res.json data
if 200 <= response.statusCode < 300
HistoryManager.injectUserDetails body, (error, data) ->
return next(error) if error?
res.json data
else
error = new Error("history api responded with non-success code: #{response.statusCode}")
logger.error err: error, user_id: user_id, "error proxying request to history api"
next(error)
buildHistoryServiceUrl: (useProjectHistory) ->
# choose a history service, either document-level (trackchanges)

View file

@ -122,7 +122,7 @@ describe "HistoryController", ->
@res =
json: sinon.stub()
@next = sinon.stub()
@request.yields(null, {}, @data = "mock-data")
@request.yields(null, {statusCode: 200}, @data = "mock-data")
@HistoryManager.injectUserDetails = sinon.stub().yields(null, @data_with_users = "mock-injected-data")
describe "for a project with the project history flag", ->
@ -182,3 +182,20 @@ describe "HistoryController", ->
it "should return the data with users to the client", ->
@res.json.calledWith(@data_with_users).should.equal true
describe "proxyToHistoryApiAndInjectUserDetails (with the history API failing)", ->
beforeEach ->
@req = { url: "/mock/url", method: "POST", useProjectHistory: true }
@res = { json: sinon.stub() }
@next = sinon.stub()
@request.yields(null, {statusCode: 500}, @data = "mock-data")
@HistoryManager.injectUserDetails = sinon.stub().yields(null, @data_with_users = "mock-injected-data")
@HistoryController.proxyToHistoryApiAndInjectUserDetails @req, @res, @next
it "should not inject the user data", ->
@HistoryManager.injectUserDetails
.calledWith(@data)
.should.equal false
it "should not return the data with users to the client", ->
@res.json.calledWith(@data_with_users).should.equal false