Merge pull request #8731 from overleaf/bg-return-not-found

[track-changes] return NotFoundError in DocumentUpdaterManager

GitOrigin-RevId: df09294d00fce0649557581554d1b7bbd88af419
This commit is contained in:
Brian Gough 2022-07-06 10:18:07 +01:00 committed by Copybot
parent 8488068a82
commit 768a5a7d0f
2 changed files with 30 additions and 1 deletions

View file

@ -14,6 +14,7 @@ let DocumentUpdaterManager
const request = require('request')
const logger = require('@overleaf/logger')
const Settings = require('@overleaf/settings')
const Errors = require('./Errors')
module.exports = DocumentUpdaterManager = {
_requestDocument(project_id, doc_id, url, callback) {
@ -46,7 +47,16 @@ module.exports = DocumentUpdaterManager = {
{ err: error, project_id, doc_id, url },
'error accessing doc updater'
)
return callback(error)
if (res.statusCode === 404) {
return callback(
new Errors.NotFoundError('doc not found', {
projectId: project_id,
docId: doc_id,
})
)
} else {
return callback(error)
}
}
})
},

View file

@ -81,6 +81,25 @@ describe('DocumentUpdaterManager', function () {
})
})
describe('when the document updater returns not found', function () {
beforeEach(function () {
this.request.get = sinon
.stub()
.callsArgWith(1, null, { statusCode: 404 }, '')
return this.DocumentUpdaterManager.getDocument(
this.project_id,
this.doc_id,
this.callback
)
})
it('should return the callback with a "not found" error', function () {
return this.callback
.calledWith(sinon.match.has('message', 'doc not found'))
.should.equal(true)
})
})
return describe('when the document updater returns a failure error code', function () {
beforeEach(function () {
this.request.get = sinon