Ver Fonte

Merge pull request #22278 from overleaf/ar-improve-history-v1-get-project-blobs-errors

[history-v1] improve getProjectBlob errors

GitOrigin-RevId: 2148f002edc3f63e0236eb139df34a22d7eb33d5
Andrew Rumble há 1 ano atrás
pai
commit
d1735f549c
1 ficheiros alterados com 11 adições e 1 exclusões
  1. 11 1
      services/history-v1/api/controllers/projects.js

+ 11 - 1
services/history-v1/api/controllers/projects.js

@@ -7,6 +7,7 @@ const HTTPStatus = require('http-status')
 const fs = require('node:fs')
 const { promisify } = require('node:util')
 const config = require('config')
+const OError = require('@overleaf/o-error')
 
 const logger = require('@overleaf/logger')
 const { Chunk, ChunkResponse, Blob } = require('overleaf-editor-core')
@@ -243,13 +244,22 @@ async function getProjectBlob(req, res, next) {
       stream = await blobStore.getStream(hash, opts)
     } catch (err) {
       if (err instanceof Blob.NotFoundError) {
+        logger.warn({ projectId, hash }, 'Blob not found')
         return res.status(404).end()
       } else {
         throw err
       }
     }
     res.set('Content-Type', 'application/octet-stream')
-    await pipeline(stream, res)
+    try {
+      await pipeline(stream, res)
+    } catch (err) {
+      if (err?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
+        res.end()
+      } else {
+        throw OError.tag(err, 'error transferring stream', { projectId, hash })
+      }
+    }
   } finally {
     logger.debug({ projectId, hash }, 'getProjectBlob finished')
   }