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

GitOrigin-RevId: 592be03d7b93a3d1f86015e58d2de5d2f12d89f6
This commit is contained in:
Domagoj Kriskovic
2026-01-28 09:08:09 +00:00
committed by Copybot
parent 56ebed8660
commit 3603bc5e25
2 changed files with 24 additions and 1 deletions
@@ -287,13 +287,14 @@ export default WebsocketController = {
projectId,
docId,
fromVersion,
function (error, { lines, version, ranges, ops, ttlInS, type }) {
function (error, result) {
if (error) {
if (error instanceof ClientRequestedMissingOpsError) {
emitJoinDocCatchUpMetrics('missing', error.info)
}
return callback(error)
}
const { lines, version, ranges, ops, ttlInS, type } = result
emitJoinDocCatchUpMetrics('success', { version, ttlInS })
if (client.disconnected) {
metrics.inc('editor.join-doc.disconnected', 1, {
@@ -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 () {
beforeEach(function (ctx) {
ctx.ranges.comments = [{ op: { a: 1 } }, { op: { a: 2 } }]