From c3fe4f1922e2d46a5ef9aa3bcd85c4701ba3860e Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Fri, 8 Nov 2024 14:30:05 +0100 Subject: [PATCH] fix: preview loading retry after 425 status code --- changelog/unreleased/bugfix-preview-retries-postprocessing | 6 ++++++ packages/web-pkg/src/services/preview/previewService.ts | 4 ++-- packages/web-pkg/tests/unit/services/previewService.spec.ts | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 changelog/unreleased/bugfix-preview-retries-postprocessing diff --git a/changelog/unreleased/bugfix-preview-retries-postprocessing b/changelog/unreleased/bugfix-preview-retries-postprocessing new file mode 100644 index 00000000000..9b2139c81f7 --- /dev/null +++ b/changelog/unreleased/bugfix-preview-retries-postprocessing @@ -0,0 +1,6 @@ +Bugfix: Preview image retries postprocessing + +Requests for preview images are now being retried when the images could not be loaded due to postprocessing. + +https://github.com/owncloud/web/issues/11870 +https://github.com/owncloud/web/pull/11874 diff --git a/packages/web-pkg/src/services/preview/previewService.ts b/packages/web-pkg/src/services/preview/previewService.ts index f1f230cffff..ebdb7b5c58f 100644 --- a/packages/web-pkg/src/services/preview/previewService.ts +++ b/packages/web-pkg/src/services/preview/previewService.ts @@ -181,7 +181,7 @@ export class PreviewService { }) return window.URL.createObjectURL(data) } catch (e) { - if (e.status === 429) { + if ([425, 429].includes(e.status)) { const retryAfter = e.response?.headers?.['retry-after'] || 5 await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000)) return this.privatePreviewBlob(options, cached, silenceErrors, signal) @@ -218,7 +218,7 @@ export class PreviewService { return previewUrl } } catch (e) { - if (e.status === 429) { + if ([425, 429].includes(e.status)) { const retryAfter = e.response?.headers?.['retry-after'] || 5 await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000)) return this.publicPreviewUrl(options, signal) diff --git a/packages/web-pkg/tests/unit/services/previewService.spec.ts b/packages/web-pkg/tests/unit/services/previewService.spec.ts index 81dccdd2065..ac3a2fc34f0 100644 --- a/packages/web-pkg/tests/unit/services/previewService.spec.ts +++ b/packages/web-pkg/tests/unit/services/previewService.spec.ts @@ -87,7 +87,7 @@ describe('PreviewService', () => { }) expect(preview).toEqual(undefined) }) - it('retries when the server returns a 429 status code', async () => { + it.each([425, 429])('retries when the server returns a %s status code', async (status) => { const supportedMimeTypes = ['image/png'] const { previewService, clientService } = getWrapper({ supportedMimeTypes, @@ -96,7 +96,7 @@ describe('PreviewService', () => { clientService.httpAuthenticated.get.mockRejectedValueOnce({ response: { headers: { 'retry-after': 0.1 } }, - status: 429 + status: status }) clientService.httpAuthenticated.get.mockResolvedValueOnce(undefined)