Просмотр исходного кода

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

[track-changes] return NotFoundError in DocumentUpdaterManager

GitOrigin-RevId: df09294d00fce0649557581554d1b7bbd88af419
Brian Gough 4 лет назад
Родитель
Сommit
768a5a7d0f

+ 11 - 1
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)
+        }
       }
     })
   },

+ 19 - 0
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