mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
[SafeJsonParse] migrate to OError and use a new DataTooLargeToParseError
This commit is contained in:
parent
f82177a46a
commit
5950b26a42
3 changed files with 13 additions and 8 deletions
|
@ -6,4 +6,13 @@ class CodedError extends OError {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = { CodedError }
|
||||
class DataTooLargeToParseError extends OError {
|
||||
constructor(data) {
|
||||
super('data too large to parse', {
|
||||
head: data.slice(0, 1024),
|
||||
length: data.length
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { CodedError, DataTooLargeToParseError }
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
const Settings = require('settings-sharelatex')
|
||||
const logger = require('logger-sharelatex')
|
||||
const { DataTooLargeToParseError } = require('./Errors')
|
||||
|
||||
module.exports = {
|
||||
parse(data, callback) {
|
||||
if (data.length > Settings.maxUpdateSize) {
|
||||
logger.error(
|
||||
{ head: data.slice(0, 1024), length: data.length },
|
||||
'data too large to parse'
|
||||
)
|
||||
return callback(new Error('data too large to parse'))
|
||||
return callback(new DataTooLargeToParseError(data))
|
||||
}
|
||||
let parsed
|
||||
try {
|
||||
|
|
|
@ -50,7 +50,7 @@ describe('SafeJsonParse', function () {
|
|||
const data = `{\"foo\": \"${big_blob}\"}`
|
||||
this.Settings.maxUpdateSize = 2 * 1024
|
||||
return this.SafeJsonParse.parse(data, (error, parsed) => {
|
||||
this.logger.error.called.should.equal(true)
|
||||
this.logger.error.called.should.equal(false)
|
||||
expect(error).to.exist
|
||||
return done()
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue