[Errors] migrate to OError

This commit is contained in:
Jakob Ackermann 2020-08-20 10:41:16 +01:00
parent c7b9dadd16
commit f82177a46a
4 changed files with 10 additions and 7 deletions

View file

@ -1,8 +1,8 @@
class CodedError extends Error {
const OError = require('@overleaf/o-error')
class CodedError extends OError {
constructor(message, code) {
super(message)
this.name = this.constructor.name
this.code = code
super(message, { code })
}
}

View file

@ -33,8 +33,8 @@ module.exports = Router = {
attrs.client_id = client.id
attrs.err = error
if (error.name === 'CodedError') {
logger.warn(attrs, error.message, { code: error.code })
const serializedError = { message: error.message, code: error.code }
logger.warn(attrs, error.message)
const serializedError = { message: error.message, code: error.info.code }
callback(serializedError)
} else if (error.message === 'unexpected arguments') {
// the payload might be very large, put it on level info

View file

@ -19,6 +19,7 @@
"format:fix": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --write"
},
"dependencies": {
"@overleaf/o-error": "^3.0.0",
"async": "^0.9.0",
"base64id": "0.1.0",
"basic-auth-connect": "^1.0.0",

View file

@ -152,7 +152,9 @@ describe('WebApiManager', function () {
.calledWith(
sinon.match({
message: 'rate-limit hit when joining project',
code: 'TooManyRequests'
info: {
code: 'TooManyRequests'
}
})
)
.should.equal(true)