diff --git a/services/real-time/app/coffee/DocumentUpdaterManager.coffee b/services/real-time/app/coffee/DocumentUpdaterManager.coffee index a2c9fe54f8..9e25585b1c 100644 --- a/services/real-time/app/coffee/DocumentUpdaterManager.coffee +++ b/services/real-time/app/coffee/DocumentUpdaterManager.coffee @@ -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 diff --git a/services/real-time/app/coffee/Router.coffee b/services/real-time/app/coffee/Router.coffee index c0e7313c39..a8bdd7c7b1 100644 --- a/services/real-time/app/coffee/Router.coffee +++ b/services/real-time/app/coffee/Router.coffee @@ -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}" diff --git a/services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee b/services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee index 8a9d335b1a..8e75da1d0c 100644 --- a/services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee +++ b/services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee @@ -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 }, "")