Files
overleaf-cep/services/project-history/app/js/DocumentUpdaterManager.js
T
Jakob Ackermann 7c70b749d4 [monorepo] remove PII and variables from error messages (#31508)
* [monorepo] remove PII and variables from error messages

Exclusions:
- scripts
- tests
- fuzzing
- SplitTestManager (messages are sent to admin frontend)
- Group setup (we may want an error per unique tuple)
- sharejs (unused types; text type errors are shadowed already)
- history-v1 error messages that are used by the ErrorRecorder
- errors that flag issues with configuration/call signatures

I've used these search terms for finding unwanted error messages:
- new Error(`
- new Error\(\n\s+` (regex search)
- new OError(`
- new OError\(\n\s+` (regex search)

* [web] throw NotFoundError from ProjectLocator

* [github-sync] fix OError.tag call in script

Co-authored-by: Jessica Lawshe <jessica.lawshe@overleaf.com>

* [templates] revert changes to test client

---------

Co-authored-by: Jessica Lawshe <jessica.lawshe@overleaf.com>
GitOrigin-RevId: 736857a4fc5d9bfb0f8cb03e0f004eda87e5a220
2026-02-17 09:05:04 +00:00

85 lines
2.4 KiB
JavaScript

/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import request from 'request'
import logger from '@overleaf/logger'
import Settings from '@overleaf/settings'
import OError from '@overleaf/o-error'
export function getDocument(projectId, docId, callback) {
if (callback == null) {
callback = function () {}
}
const url = `${Settings.apis.documentupdater.url}/project/${projectId}/doc/${docId}`
logger.debug({ projectId, docId }, 'getting doc from document updater')
return request.get(url, function (error, res, body) {
if (error != null) {
return callback(OError.tag(error))
}
if (res.statusCode >= 200 && res.statusCode < 300) {
try {
body = JSON.parse(body)
} catch (error1) {
error = error1
return callback(error)
}
logger.debug(
{ projectId, docId, version: body.version },
'got doc from document updater'
)
return callback(null, body.lines.join('\n'), body.version)
} else {
error = new OError('doc updater returned a non-success status code', {
project_id: projectId,
doc_id: docId,
url,
statusCode: res.statusCode,
})
return callback(error)
}
})
}
export function setDocument(projectId, docId, content, userId, callback) {
if (callback == null) {
callback = function () {}
}
const url = `${Settings.apis.documentupdater.url}/project/${projectId}/doc/${docId}`
logger.debug({ projectId, docId }, 'setting doc in document updater')
return request.post(
{
url,
json: {
lines: content.split('\n'),
source: 'restore',
user_id: userId,
undoing: true,
},
},
function (error, res, body) {
if (error != null) {
return callback(OError.tag(error))
}
if (res.statusCode >= 200 && res.statusCode < 300) {
return callback(null)
} else {
error = new OError('doc updater returned a non-success status code', {
project_id: projectId,
doc_id: docId,
url,
statusCode: res.statusCode,
})
return callback(error)
}
}
)
}