diff --git a/services/real-time/app/js/DocumentUpdaterManager.js b/services/real-time/app/js/DocumentUpdaterManager.js index 3fd09d7b1d..8a2ebda1f9 100644 --- a/services/real-time/app/js/DocumentUpdaterManager.js +++ b/services/real-time/app/js/DocumentUpdaterManager.js @@ -6,6 +6,7 @@ const _ = require('underscore') const logger = require('logger-sharelatex') const settings = require('settings-sharelatex') const metrics = require('metrics-sharelatex') +const { UpdateTooLargeError } = require('./Errors') const rclient = require('redis-sharelatex').createClient( settings.redis.documentupdater @@ -125,9 +126,7 @@ const DocumentUpdaterManager = { const updateSize = jsonChange.length if (updateSize > settings.maxUpdateSize) { - const error = new Error('update is too large') - error.updateSize = updateSize - return callback(error) + return callback(new UpdateTooLargeError(updateSize)) } // record metric for each update added to queue diff --git a/services/real-time/app/js/Errors.js b/services/real-time/app/js/Errors.js index 12c644c839..56034023a0 100644 --- a/services/real-time/app/js/Errors.js +++ b/services/real-time/app/js/Errors.js @@ -15,4 +15,10 @@ class DataTooLargeToParseError extends OError { } } -module.exports = { CodedError, DataTooLargeToParseError } +class UpdateTooLargeError extends OError { + constructor(updateSize) { + super('update is too large', { updateSize }) + } +} + +module.exports = { CodedError, DataTooLargeToParseError, UpdateTooLargeError } diff --git a/services/real-time/app/js/WebsocketController.js b/services/real-time/app/js/WebsocketController.js index 8867320dbe..a0c33f5cbe 100644 --- a/services/real-time/app/js/WebsocketController.js +++ b/services/real-time/app/js/WebsocketController.js @@ -509,7 +509,7 @@ module.exports = WebsocketController = { function (error) { if ((error && error.message) === 'update is too large') { metrics.inc('update_too_large') - const { updateSize } = error + const { updateSize } = error.info logger.warn( { user_id, project_id, doc_id, updateSize }, 'update is too large' diff --git a/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js b/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js index dc42b52140..2ded504051 100644 --- a/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js +++ b/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js @@ -346,7 +346,7 @@ describe('DocumentUpdaterManager', function () { }) it('should add the size to the error', function () { - return this.callback.args[0][0].updateSize.should.equal(7782422) + return this.callback.args[0][0].info.updateSize.should.equal(7782422) }) return it('should not push the change onto the pending-updates-list queue', function () { diff --git a/services/real-time/test/unit/js/WebsocketControllerTests.js b/services/real-time/test/unit/js/WebsocketControllerTests.js index 515d407cc2..7c42dd6256 100644 --- a/services/real-time/test/unit/js/WebsocketControllerTests.js +++ b/services/real-time/test/unit/js/WebsocketControllerTests.js @@ -19,6 +19,7 @@ const { expect } = chai const modulePath = '../../../app/js/WebsocketController.js' const SandboxedModule = require('sandboxed-module') const tk = require('timekeeper') +const { UpdateTooLargeError } = require('../../../app/js/Errors') describe('WebsocketController', function () { beforeEach(function () { @@ -1507,8 +1508,7 @@ describe('WebsocketController', function () { this.client.emit = sinon.stub() this.client.ol_context.user_id = this.user_id this.client.ol_context.project_id = this.project_id - const error = new Error('update is too large') - error.updateSize = 7372835 + const error = new UpdateTooLargeError(7372835) this.DocumentUpdaterManager.queueChange = sinon .stub() .callsArgWith(3, error)