From 4cb8cc4a85935031de4c3bf5922247e2e46ae3f7 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Thu, 20 Aug 2020 12:59:52 +0100 Subject: [PATCH] [DocumentUpdaterManager] use a new ClientRequestedMissingOpsError --- .../real-time/app/js/DocumentUpdaterManager.js | 9 ++------- services/real-time/app/js/Errors.js | 9 +++++++++ .../test/unit/js/DocumentUpdaterManagerTests.js | 16 +++++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/services/real-time/app/js/DocumentUpdaterManager.js b/services/real-time/app/js/DocumentUpdaterManager.js index 1b99ed7ab4..67ecd82c29 100644 --- a/services/real-time/app/js/DocumentUpdaterManager.js +++ b/services/real-time/app/js/DocumentUpdaterManager.js @@ -7,6 +7,7 @@ const logger = require('logger-sharelatex') const settings = require('settings-sharelatex') const metrics = require('metrics-sharelatex') const { + ClientRequestedMissingOpsError, DocumentUpdaterRequestFailedError, NullBytesInOpError, UpdateTooLargeError @@ -47,13 +48,7 @@ const DocumentUpdaterManager = { body = body || {} callback(null, body.lines, body.version, body.ranges, body.ops) } else if ([404, 422].includes(res.statusCode)) { - 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) + callback(new ClientRequestedMissingOpsError(res.statusCode)) } else { callback( new DocumentUpdaterRequestFailedError('getDocument', res.statusCode) diff --git a/services/real-time/app/js/Errors.js b/services/real-time/app/js/Errors.js index 1e6ffbd4ef..24c0b3d316 100644 --- a/services/real-time/app/js/Errors.js +++ b/services/real-time/app/js/Errors.js @@ -1,5 +1,13 @@ const OError = require('@overleaf/o-error') +class ClientRequestedMissingOpsError extends OError { + constructor(statusCode) { + super('doc updater could not load requested ops', { + statusCode + }) + } +} + class CodedError extends OError { constructor(message, code) { super(message, { code }) @@ -63,6 +71,7 @@ class WebApiRequestFailedError extends OError { module.exports = { CodedError, CorruptedJoinProjectResponseError, + ClientRequestedMissingOpsError, DataTooLargeToParseError, DocumentUpdaterRequestFailedError, MissingSessionError, diff --git a/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js b/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js index f5023b3e30..828f516364 100644 --- a/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js +++ b/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js @@ -136,14 +136,16 @@ describe('DocumentUpdaterManager', function () { return it('should return the callback with an error', function () { this.callback.called.should.equal(true) - const err = this.callback.getCall(0).args[0] - err.should.have.property('statusCode', statusCode) - err.should.have.property( - 'message', - 'doc updater could not load requested ops' - ) + this.callback + .calledWith( + sinon.match({ + message: 'doc updater could not load requested ops', + info: { statusCode } + }) + ) + .should.equal(true) this.logger.error.called.should.equal(false) - return this.logger.warn.called.should.equal(true) + this.logger.warn.called.should.equal(false) }) }) )