From aac9e6616e3795ef4c1dae905596f881331fec4b Mon Sep 17 00:00:00 2001 From: Mathias Jakobsen Date: Thu, 3 Nov 2022 12:45:11 +0000 Subject: [PATCH] Merge pull request #10285 from overleaf/jpa-pdf-caching-ignore-404-from-fallback [web] pdf-caching: double down on ignoring 404 from output.pdf requests GitOrigin-RevId: 6b489180c221a29758b862884dae4ed6ed954a23 --- .../pdf-preview/util/pdf-caching-transport.js | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/services/web/frontend/js/features/pdf-preview/util/pdf-caching-transport.js b/services/web/frontend/js/features/pdf-preview/util/pdf-caching-transport.js index 3ca0fe0faf..7afce81fd2 100644 --- a/services/web/frontend/js/features/pdf-preview/util/pdf-caching-transport.js +++ b/services/web/frontend/js/features/pdf-preview/util/pdf-caching-transport.js @@ -62,6 +62,10 @@ export function generatePdfCachingTransportFactory(PDFJS) { end, metrics, } + const is404onOutputPDF = err => + err.message === 'non successful response status: 404' && + OError.getFullInfo(err).url === this.url + fetchRange({ url: this.url, start, @@ -78,10 +82,7 @@ export function generatePdfCachingTransportFactory(PDFJS) { }) .catch(err => { if (abortSignal.aborted) return - if ( - err.message === 'non successful response status: 404' && - OError.getFullInfo(err).url === this.url - ) { + if (is404onOutputPDF(err)) { // Do not consider a 404 on the main pdf url as pdf caching failure. throw new PDFJS.MissingPDFException() } @@ -93,7 +94,18 @@ export function generatePdfCachingTransportFactory(PDFJS) { err = OError.tag(err, 'optimized pdf download error', errorInfo) console.error(err) captureException(err, { tags: { fromPdfCaching: true } }) - return fallbackRequest({ url: this.url, start, end, abortSignal }) + return fallbackRequest({ + url: this.url, + start, + end, + abortSignal, + }).catch(err => { + if (is404onOutputPDF(err)) { + // Do not consider a 404 on the main pdf url as pdf caching failure. + err = new PDFJS.MissingPDFException() + } + throw err + }) }) .then(blob => { if (abortSignal.aborted) return