diff --git a/services/real-time/app/js/Errors.js b/services/real-time/app/js/Errors.js index 57190b75e5..5b41334fb3 100644 --- a/services/real-time/app/js/Errors.js +++ b/services/real-time/app/js/Errors.js @@ -39,11 +39,18 @@ class UpdateTooLargeError extends OError { } } +class WebApiRequestFailedError extends OError { + constructor(statusCode) { + super('non-success status code from web', { statusCode }) + } +} + module.exports = { CodedError, DataTooLargeToParseError, MissingSessionError, NotAuthorizedError, NullBytesInOpError, - UpdateTooLargeError + UpdateTooLargeError, + WebApiRequestFailedError } diff --git a/services/real-time/app/js/WebApiManager.js b/services/real-time/app/js/WebApiManager.js index 62020a98ab..dffcca51c8 100644 --- a/services/real-time/app/js/WebApiManager.js +++ b/services/real-time/app/js/WebApiManager.js @@ -4,7 +4,7 @@ const request = require('request') const settings = require('settings-sharelatex') const logger = require('logger-sharelatex') -const { CodedError } = require('./Errors') +const { CodedError, WebApiRequestFailedError } = require('./Errors') module.exports = { joinProject(project_id, user, callback) { @@ -57,11 +57,7 @@ module.exports = { ) ) } else { - err = new Error( - `non-success status code from web: ${response.statusCode}` - ) - logger.error({ err, project_id, user_id }, 'error accessing web api') - callback(err) + callback(new WebApiRequestFailedError(response.statusCode)) } } ) diff --git a/services/real-time/test/unit/js/WebApiManagerTests.js b/services/real-time/test/unit/js/WebApiManagerTests.js index 52c6da137a..4435bc14f9 100644 --- a/services/real-time/test/unit/js/WebApiManagerTests.js +++ b/services/real-time/test/unit/js/WebApiManagerTests.js @@ -106,7 +106,10 @@ describe('WebApiManager', function () { return it('should call the callback with an error', function () { return this.callback .calledWith( - sinon.match({ message: 'non-success status code from web: 500' }) + sinon.match({ + message: 'non-success status code from web', + info: { statusCode: 500 } + }) ) .should.equal(true) })