Sfoglia il codice sorgente

[DocumentUpdaterManager] use a new UpdateTooLargeError

Jakob Ackermann 6 anni fa
parent
commit
af50f9b02c

+ 2 - 3
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

+ 7 - 1
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 }

+ 1 - 1
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'

+ 1 - 1
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 () {

+ 2 - 2
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)