Skip to content

Commit

Permalink
Wrap cache query ni a try/catch
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Sep 20, 2023
1 parent fc3c7d6 commit 083998b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/services/PreviewService.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ const SWCacheName = 'images'
* Check if the preview is already cached by the service worker
*
* @param {string} previewUrl - The URL of the preview to check
* @return {Promise<boolean>}
*/
export const isCachedPreview = async function(previewUrl) {
const cache = await window.caches?.open(SWCacheName)
const response = await cache?.match(previewUrl)
return response !== undefined
try {
const cache = await window.caches?.open(SWCacheName)
const response = await cache?.match(previewUrl)
return response !== undefined
} catch {
return false
}
}

0 comments on commit 083998b

Please sign in to comment.