Skip to content

Commit

Permalink
Merge pull request #11882 from owncloud/fix/pick-preview-retry-on-425
Browse files Browse the repository at this point in the history
fix: preview loading retry after 425 status code
  • Loading branch information
JammingBen authored Nov 11, 2024
2 parents 4c348f6 + c3fe4f1 commit e12870e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-preview-retries-postprocessing
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions packages/web-pkg/src/services/preview/previewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/web-pkg/tests/unit/services/previewService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down

0 comments on commit e12870e

Please sign in to comment.