mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-22 02:18:27 +00:00
Merge pull request #22278 from overleaf/ar-improve-history-v1-get-project-blobs-errors
[history-v1] improve getProjectBlob errors GitOrigin-RevId: 2148f002edc3f63e0236eb139df34a22d7eb33d5
This commit is contained in:
parent
172aeb59d1
commit
d1735f549c
1 changed files with 11 additions and 1 deletions
|
@ -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')
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue