From 768a5a7d0f267e79b0b3c18e85d2b9af52efa577 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 6 Jul 2022 10:18:07 +0100 Subject: [PATCH] Merge pull request #8731 from overleaf/bg-return-not-found [track-changes] return NotFoundError in DocumentUpdaterManager GitOrigin-RevId: df09294d00fce0649557581554d1b7bbd88af419 --- .../app/js/DocumentUpdaterManager.js | 12 +++++++++++- .../DocumentUpdaterManagerTests.js | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/services/track-changes/app/js/DocumentUpdaterManager.js b/services/track-changes/app/js/DocumentUpdaterManager.js index 24ccf96304..69dae684a2 100644 --- a/services/track-changes/app/js/DocumentUpdaterManager.js +++ b/services/track-changes/app/js/DocumentUpdaterManager.js @@ -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) + } } }) }, diff --git a/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js b/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js index 8221f98d06..1f6fae8651 100644 --- a/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js +++ b/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js @@ -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