Forráskód Böngészése

[real-time] handle getDocument result in case of an error

GitOrigin-RevId: 592be03d7b93a3d1f86015e58d2de5d2f12d89f6
Domagoj Kriskovic 6 hónapja
szülő
commit
3603bc5e25

+ 2 - 1
services/real-time/app/js/WebsocketController.js

@@ -287,13 +287,14 @@ export default WebsocketController = {
             projectId,
             projectId,
             docId,
             docId,
             fromVersion,
             fromVersion,
-            function (error, { lines, version, ranges, ops, ttlInS, type }) {
+            function (error, result) {
               if (error) {
               if (error) {
                 if (error instanceof ClientRequestedMissingOpsError) {
                 if (error instanceof ClientRequestedMissingOpsError) {
                   emitJoinDocCatchUpMetrics('missing', error.info)
                   emitJoinDocCatchUpMetrics('missing', error.info)
                 }
                 }
                 return callback(error)
                 return callback(error)
               }
               }
+              const { lines, version, ranges, ops, ttlInS, type } = result
               emitJoinDocCatchUpMetrics('success', { version, ttlInS })
               emitJoinDocCatchUpMetrics('success', { version, ttlInS })
               if (client.disconnected) {
               if (client.disconnected) {
                 metrics.inc('editor.join-doc.disconnected', 1, {
                 metrics.inc('editor.join-doc.disconnected', 1, {

+ 22 - 0
services/real-time/test/unit/js/WebsocketController.test.js

@@ -728,6 +728,28 @@ describe('WebsocketController', function () {
       })
       })
     })
     })
 
 
+    describe('when the DocumentUpdaterManager returns an error', function () {
+      beforeEach(function (ctx) {
+        ctx.err = new Error('document updater error')
+        ctx.DocumentUpdaterManager.getDocument = sinon
+          .stub()
+          .callsArgWith(3, ctx.err)
+        ctx.WebsocketController.joinDoc(
+          ctx.client,
+          ctx.doc_id,
+          -1,
+          ctx.options,
+          ctx.callback
+        )
+      })
+
+      it('should call the callback with the error', function (ctx) {
+        ctx.callback
+          .calledWith(sinon.match({ message: 'document updater error' }))
+          .should.equal(true)
+      })
+    })
+
     describe('with a restricted client', function () {
     describe('with a restricted client', function () {
       beforeEach(function (ctx) {
       beforeEach(function (ctx) {
         ctx.ranges.comments = [{ op: { a: 1 } }, { op: { a: 2 } }]
         ctx.ranges.comments = [{ op: { a: 1 } }, { op: { a: 2 } }]