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

[DocumentUpdaterManager] use a new ClientRequestedMissingOpsError

Jakob Ackermann 6 лет назад
Родитель
Сommit
4cb8cc4a85

+ 2 - 7
services/real-time/app/js/DocumentUpdaterManager.js

@@ -7,6 +7,7 @@ const logger = require('logger-sharelatex')
 const settings = require('settings-sharelatex')
 const metrics = require('metrics-sharelatex')
 const {
+  ClientRequestedMissingOpsError,
   DocumentUpdaterRequestFailedError,
   NullBytesInOpError,
   UpdateTooLargeError
@@ -47,13 +48,7 @@ const DocumentUpdaterManager = {
         body = body || {}
         callback(null, body.lines, body.version, body.ranges, body.ops)
       } else if ([404, 422].includes(res.statusCode)) {
-        err = new Error('doc updater could not load requested ops')
-        err.statusCode = res.statusCode
-        logger.warn(
-          { err, project_id, doc_id, url, fromVersion },
-          'doc updater could not load requested ops'
-        )
-        callback(err)
+        callback(new ClientRequestedMissingOpsError(res.statusCode))
       } else {
         callback(
           new DocumentUpdaterRequestFailedError('getDocument', res.statusCode)

+ 9 - 0
services/real-time/app/js/Errors.js

@@ -1,5 +1,13 @@
 const OError = require('@overleaf/o-error')
 
+class ClientRequestedMissingOpsError extends OError {
+  constructor(statusCode) {
+    super('doc updater could not load requested ops', {
+      statusCode
+    })
+  }
+}
+
 class CodedError extends OError {
   constructor(message, code) {
     super(message, { code })
@@ -63,6 +71,7 @@ class WebApiRequestFailedError extends OError {
 module.exports = {
   CodedError,
   CorruptedJoinProjectResponseError,
+  ClientRequestedMissingOpsError,
   DataTooLargeToParseError,
   DocumentUpdaterRequestFailedError,
   MissingSessionError,

+ 9 - 7
services/real-time/test/unit/js/DocumentUpdaterManagerTests.js

@@ -136,14 +136,16 @@ describe('DocumentUpdaterManager', function () {
 
         return it('should return the callback with an error', function () {
           this.callback.called.should.equal(true)
-          const err = this.callback.getCall(0).args[0]
-          err.should.have.property('statusCode', statusCode)
-          err.should.have.property(
-            'message',
-            'doc updater could not load requested ops'
-          )
+          this.callback
+            .calledWith(
+              sinon.match({
+                message: 'doc updater could not load requested ops',
+                info: { statusCode }
+              })
+            )
+            .should.equal(true)
           this.logger.error.called.should.equal(false)
-          return this.logger.warn.called.should.equal(true)
+          this.logger.warn.called.should.equal(false)
         })
       })
     )