Merge pull request #5997 from overleaf/em-track-changes-docstore-404

Skip inexistent docs when building ShareLaTeX history

GitOrigin-RevId: 5b7c5b77623d77c7d20f852050249211de0c8cb3
This commit is contained in:
Eric Mc Sween 2021-12-03 08:15:37 -05:00 committed by Copybot
parent be17e022a6
commit 98a4742c0a
3 changed files with 28 additions and 7 deletions

View file

@ -1,6 +1,7 @@
const request = require('request')
const logger = require('logger-sharelatex')
const Settings = require('@overleaf/settings')
const Errors = require('./Errors')
function peekDocument(projectId, docId, callback) {
const url = `${Settings.apis.docstore.url}/project/${projectId}/doc/${docId}/peek`
@ -15,8 +16,7 @@ function peekDocument(projectId, docId, callback) {
if (res.statusCode >= 200 && res.statusCode < 300) {
try {
body = JSON.parse(body)
} catch (error1) {
error = error1
} catch (error) {
return callback(error)
}
logger.log(
@ -24,6 +24,10 @@ function peekDocument(projectId, docId, callback) {
'got doc from docstore'
)
return callback(null, body.lines.join('\n'), body.version)
} else if (res.statusCode === 404) {
return callback(
new Errors.NotFoundError('doc not found', { projectId, docId })
)
} else {
return callback(
new Error(

View file

@ -0,0 +1,5 @@
const OError = require('@overleaf/o-error')
class NotFoundError extends OError {}
module.exports = { NotFoundError }

View file

@ -3,6 +3,7 @@ const UpdatesManager = require('./UpdatesManager')
const DiffGenerator = require('./DiffGenerator')
const DocumentUpdaterManager = require('./DocumentUpdaterManager')
const DocstoreManager = require('./DocstoreManager')
const Errors = require('./Errors')
const PackManager = require('./PackManager')
const yazl = require('yazl')
const util = require('util')
@ -47,11 +48,22 @@ async function rewindDoc(projectId, docId, zipfile) {
const lastUpdateVersion = lastUpdate.v
const [latestContent, version] = await getLatestContent(
let latestContent
let version
try {
;[latestContent, version] = await getLatestContent(
projectId,
docId,
lastUpdateVersion
)
} catch (err) {
if (err instanceof Errors.NotFoundError) {
// Doc not found in docstore. We can't build its history
return null
} else {
throw err
}
}
const id = docId.toString()