mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
fix: add error handling to sw-dev.js fetch requests
Add proper error handling to prevent uncaught promise rejections when image fetches fail. If a fetch fails, try to return cached response, or gracefully handle the error instead of letting it propagate as an uncaught promise rejection.
This commit is contained in:
@@ -28,8 +28,16 @@ self.addEventListener('fetch', (event) => {
|
||||
cache.put(event.request, response.clone())
|
||||
}
|
||||
return response
|
||||
}).catch((error) => {
|
||||
// If fetch fails (network error, CORS, etc.), return cached response if available
|
||||
// or let the error propagate so the browser can handle it
|
||||
// Don't cache failed responses
|
||||
return cachedResponse || Promise.reject(error)
|
||||
})
|
||||
})
|
||||
}).catch(() => {
|
||||
// If cache.open or match fails, try to fetch directly without caching
|
||||
return fetch(event.request)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user