Return semantic error if doc ops range is not loaded

This commit is contained in:
James Allen 2016-05-31 14:21:23 +01:00
parent f4a465ea69
commit 51939512ac
3 changed files with 20 additions and 3 deletions

View file

@ -23,6 +23,11 @@ module.exports = DocumentUpdaterManager =
catch error
return callback(error)
callback null, body?.lines, body?.version, body?.ops
else if res.statusCode == 422 # Unprocessable Entity
err = new Error("doc updater could not load requested ops")
err.statusCode = res.statusCode
logger.warn {err, project_id, doc_id, url, fromVersion}, "doc updater could not load requested ops"
callback err
else
err = new Error("doc updater returned a non-success status code: #{res.statusCode}")
err.statusCode = res.statusCode

View file

@ -21,8 +21,8 @@ module.exports = Router =
attrs[key] = value
attrs.client_id = client.id
attrs.err = error
if error.message == "not authorized"
logger.warn attrs, "client is not authorized"
if error.message in ["not authorized", "doc updater could not load requested ops"]
logger.warn attrs, error.message
return callback {message: error.message}
else
logger.error attrs, "server side error in #{method}"

View file

@ -17,7 +17,7 @@ describe 'DocumentUpdaterManager', ->
@DocumentUpdaterManager = SandboxedModule.require modulePath, requires:
'settings-sharelatex':@settings
'logger-sharelatex': @logger = {log: sinon.stub(), error: sinon.stub()}
'logger-sharelatex': @logger = {log: sinon.stub(), error: sinon.stub(), warn: sinon.stub()}
'request': @request = {}
'redis-sharelatex' : createClient: () => @rclient
@ -50,6 +50,18 @@ describe 'DocumentUpdaterManager', ->
it "should return an error to the callback", ->
@callback.calledWith(@error).should.equal true
describe "when the document updater returns a 422 status code", ->
beforeEach ->
@request.get = sinon.stub().callsArgWith(1, null, { statusCode: 422 }, "")
@DocumentUpdaterManager.getDocument @project_id, @doc_id, @fromVersion, @callback
it "should return the callback with an error", ->
err = new Error("doc updater could not load requested ops")
err.statusCode = 422
@callback
.calledWith(err)
.should.equal true
describe "when the document updater returns a failure error code", ->
beforeEach ->
@request.get = sinon.stub().callsArgWith(1, null, { statusCode: 500 }, "")