Skip to content

Commit

Permalink
fix: preview loading retry after 425 status code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannik Stehle committed Nov 8, 2024
1 parent dda9c2f commit 24eedd1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 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
45 changes: 24 additions & 21 deletions packages/web-pkg/tests/unit/services/previewService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,33 @@ describe('PreviewService', () => {
})
expect(preview).toEqual(undefined)
})
it('retries when the server returns a 429 status code', async () => {
const supportedMimeTypes = ['image/png']
const { previewService, clientService } = getWrapper({
supportedMimeTypes,
version: '1'
})
it.each([425, 429])(
'retries when the server returns a 425 or 429 status code',
async (status) => {
const supportedMimeTypes = ['image/png']
const { previewService, clientService } = getWrapper({
supportedMimeTypes,
version: '1'
})

clientService.httpAuthenticated.get.mockRejectedValueOnce({
response: { headers: { 'retry-after': 0.1 } },
status: 429
})
clientService.httpAuthenticated.get.mockResolvedValueOnce(undefined)
clientService.httpAuthenticated.get.mockRejectedValueOnce({
response: { headers: { 'retry-after': 0.1 } },
status: status
})
clientService.httpAuthenticated.get.mockResolvedValueOnce(undefined)

await previewService.loadPreview({
space: mock<SpaceResource>(),
resource: mock<Resource>({
mimeType: supportedMimeTypes[0],
webDavPath: '/',
etag: '',
canDownload: () => true
await previewService.loadPreview({
space: mock<SpaceResource>(),
resource: mock<Resource>({
mimeType: supportedMimeTypes[0],
webDavPath: '/',
etag: '',
canDownload: () => true
})
})
})
expect(clientService.httpAuthenticated.get).toHaveBeenCalledTimes(2)
})
expect(clientService.httpAuthenticated.get).toHaveBeenCalledTimes(2)
}
)
describe('private files', () => {
it('loads preview', async () => {
const objectUrl = 'objectUrl'
Expand Down

0 comments on commit 24eedd1

Please sign in to comment.