[DocumentUpdaterManager] use a new UpdateTooLargeError

This commit is contained in:
Jakob Ackermann 2020-08-20 11:16:26 +01:00
parent 5950b26a42
commit af50f9b02c
5 changed files with 13 additions and 8 deletions

View file

@ -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

View file

@ -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 }

View file

@ -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'

View file

@ -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 () {

View file

@ -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)