@geogirafe/lib-geoportal 1.3.0-dev.3079206142 → 1.3.0-dev.3102381424

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "GeoGirafe PSC",
6
6
  "url": "https://doc.geogirafe.org"
7
7
  },
8
- "version": "1.3.0-dev.3079206142",
8
+ "version": "1.3.0-dev.3102381424",
9
9
  "type": "module",
10
10
  "engines": {
11
11
  "node": ">=20.19.0"
@@ -1 +1 @@
1
- {"version":"1.3.0-dev.3079206142", "build":"3079206142", "date":"17/11/2026"}
1
+ {"version":"1.3.0-dev.3102381424", "build":"3102381424", "date":"23/11/2026"}
@@ -69,10 +69,11 @@ export declare class CacheHelper {
69
69
  private readonly maxCacheCount;
70
70
  private cacheCount;
71
71
  /**
72
- * Execute a fetch for the query, and cache the result if successful
73
- * Returns null if unsuccessful
72
+ * Execute a fetch for the query, and cache the result if successful.
73
+ * Network errors (offline, DNS, CORS...) are propagated to the caller.
74
+ * A failure while caching does not discard the server response.
74
75
  */
75
- fetchAndCache(state: SwState, request: Request): Promise<Response | null>;
76
+ fetchAndCache(state: SwState, request: Request): Promise<Response>;
76
77
  /**
77
78
  * Try to load this request from local cache.
78
79
  * Returns null if unsuccessful
@@ -277,28 +277,27 @@ export class CacheHelper {
277
277
  maxCacheCount = 300; // Number of queries that should be cached by the service-worker for offline usage.
278
278
  cacheCount = 0; // Counter related to the max value above
279
279
  /**
280
- * Execute a fetch for the query, and cache the result if successful
281
- * Returns null if unsuccessful
280
+ * Execute a fetch for the query, and cache the result if successful.
281
+ * Network errors (offline, DNS, CORS...) are propagated to the caller.
282
+ * A failure while caching does not discard the server response.
282
283
  */
283
284
  async fetchAndCache(state, request) {
284
- try {
285
- const response = await fetch(request);
286
- if (this.cacheCount < this.maxCacheCount &&
287
- this.isCacheAllowed(request) &&
288
- response.ok &&
289
- response.type !== 'opaque') {
290
- // Fetch was successful. We cache the result if necessary and return the response.
291
- this.cacheCount++;
292
- swLog(state, `${this.cacheCount}/${this.maxCacheCount} caching ${request.url} for offline use.`);
293
- const copy = response.clone();
285
+ const response = await fetch(request);
286
+ if (this.cacheCount < this.maxCacheCount &&
287
+ this.isCacheAllowed(request) &&
288
+ response.ok &&
289
+ response.type !== 'opaque') {
290
+ this.cacheCount++;
291
+ swLog(state, `${this.cacheCount}/${this.maxCacheCount} caching ${request.url} for offline use.`);
292
+ try {
294
293
  const cache = await caches.open(this.appCacheName);
295
- await cache.put(request, copy);
294
+ await cache.put(request, response.clone());
295
+ }
296
+ catch (error) {
297
+ swLog(state, `Failed to cache ${request.url}`, error);
296
298
  }
297
- return response;
298
- }
299
- catch {
300
- return null;
301
299
  }
300
+ return response;
302
301
  }
303
302
  /**
304
303
  * Try to load this request from local cache.
@@ -74,19 +74,25 @@ function handleActivate(event) {
74
74
  async function handleFetchEvent(event) {
75
75
  await swHelperReady;
76
76
  const newRequest = swHelper.getRequest(event.request);
77
- let response = await cacheHelper.fetchAndCache(swHelper.State, newRequest);
78
- // Use cache only for GET queries
79
- if (cacheHelper.isCacheAllowed(event.request)) {
80
- if (!response) {
81
- // Fetch was unsuccessful. We try to load the data from cache.
82
- response = await cacheHelper.loadFromCache(event.request);
83
- }
84
- if (!response) {
85
- // Not found in cache. We try to load from IndexedDB.
86
- response = await indexDbHelper.loadFromIndexedDB(swHelper.State, event.request);
77
+ try {
78
+ return await cacheHelper.fetchAndCache(swHelper.State, newRequest);
79
+ }
80
+ catch (error) {
81
+ const offlineResponse = await loadOfflineResponse(event.request);
82
+ if (offlineResponse) {
83
+ return offlineResponse;
87
84
  }
85
+ log(`Fetch failed for ${event.request.method} ${event.request.url}`, error);
86
+ throw error;
87
+ }
88
+ }
89
+ async function loadOfflineResponse(request) {
90
+ // Use cache only for GET queries
91
+ if (!cacheHelper.isCacheAllowed(request)) {
92
+ return null;
88
93
  }
89
- return response ?? new Response(null, { status: 503 });
94
+ const cachedResponse = await cacheHelper.loadFromCache(request);
95
+ return cachedResponse ?? (await indexDbHelper.loadFromIndexedDB(swHelper.State, request));
90
96
  }
91
97
  function log(str, error) {
92
98
  swLog(swHelper.State, str, error);