{"record":{"id":"0b4d6ab2c55b38a0","repo":"overleaf/overleaf","slug":"entity-not-found-when-downloading-doc","errorCode":null,"errorMessage":"entity not found when downloading doc","messagePattern":"entity not found when downloading doc","errorType":"http","errorClass":"NotFoundError","httpStatus":404,"severity":"error","filePath":"services/web/app/src/Features/DocumentUpdater/DocumentUpdaterController.mjs","lineNumber":28,"sourceCode":"\n  try {\n    const { element: doc } = await ProjectLocator.promises.findElement({\n      project_id: projectId,\n      element_id: docId,\n      type: 'doc',\n    })\n\n    const { lines } = await DocumentUpdaterHandler.promises.getDocument(\n      projectId,\n      docId,\n      -1 // latest version only\n    )\n\n    res.setContentDisposition('attachment', { filename: doc.name })\n    plainTextResponse(res, lines.join('\\n'))\n  } catch (err) {\n    if (err.name === 'NotFoundError') {\n      logger.warn(\n        { err, projectId, docId },\n        'entity not found when downloading doc'\n      )\n\n      return res.sendStatus(404)\n    }\n\n    logger.err(\n      { err, projectId, docId },\n      'error getting document for downloading'\n    )\n\n    return res.sendStatus(500)\n  }\n}\n\nexport default {\n  getDoc: expressify(getDoc),","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/overleaf/overleaf/blob/28ad3b03b71cb4311decdcb55c36b33ec10d72db/services/web/app/src/Features/DocumentUpdater/DocumentUpdaterController.mjs#L10-L46","documentation":"NotFoundError propagated by ProjectLocator.promises.findElement when no doc entity matches the given docId in the project — typically a stale URL, a doc deleted in another tab, or a project/doc id mismatch. The handler logs it as a warning because a missing entity is an expected client-side condition, not a server fault.","triggerScenarios":"Thrown at services/web/app/src/Features/DocumentUpdater/DocumentUpdaterController.mjs:28 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the projectId and docId pair actually exists in Mongo before exporting","Check that the doc was not deleted or renamed between the listing request and the download request","Return a 404 to the caller with a localized 'document not found' message"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"28ad3b03b71cb4311decdcb55c36b33ec10d72db","analyzedAt":"2026-09-03T02:10:22.807Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}