mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
[DocumentUpdaterManager] use a new UpdateTooLargeError
This commit is contained in:
parent
5950b26a42
commit
af50f9b02c
5 changed files with 13 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue