@sjcrh/proteinpaint-shared 2.170.13 → 2.170.21
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 +1 -1
- package/src/fetch-helpers.js +22 -17
package/package.json
CHANGED
package/src/fetch-helpers.js
CHANGED
|
@@ -223,22 +223,27 @@ export async function memFetch(url, init, opts = {}) {
|
|
|
223
223
|
dataCache.set(dataKey, { response, exp: Date.now() + cacheLifetime })
|
|
224
224
|
return response
|
|
225
225
|
})
|
|
226
|
-
: fetch(url, init)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
226
|
+
: fetch(url, init)
|
|
227
|
+
.then(async r => {
|
|
228
|
+
const response = await processResponse(r)
|
|
229
|
+
if (!r.ok) {
|
|
230
|
+
console.trace(response)
|
|
231
|
+
throw (
|
|
232
|
+
'memFetch error ' +
|
|
233
|
+
r.status +
|
|
234
|
+
': ' +
|
|
235
|
+
(typeof response == 'object' ? response.message || response.error : response)
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
// replace the cached promise result with the actual data,
|
|
239
|
+
// since persisting a cached promise for a long time is likely not best practice
|
|
240
|
+
dataCache.set(dataKey, { response: deepFreeze(response), exp: Date.now() + cacheLifetime })
|
|
241
|
+
return response
|
|
242
|
+
})
|
|
243
|
+
.catch(e => {
|
|
244
|
+
if (dataCache.get(dataKey)) dataCache.delete(dataKey)
|
|
245
|
+
throw e
|
|
246
|
+
})
|
|
242
247
|
|
|
243
248
|
dataCache.set(dataKey, { response: result, exp: Date.now() + cacheLifetime })
|
|
244
249
|
manageCacheSize(now)
|
|
@@ -246,7 +251,7 @@ export async function memFetch(url, init, opts = {}) {
|
|
|
246
251
|
} catch (e) {
|
|
247
252
|
// delete this cache only if it is a promise;
|
|
248
253
|
// do not delete a valid resolved data cache
|
|
249
|
-
if (dataCache.get(dataKey) instanceof Promise)
|
|
254
|
+
if (dataCache.get(dataKey) instanceof Promise) dataCache.delete(dataKey)
|
|
250
255
|
throw e
|
|
251
256
|
}
|
|
252
257
|
}
|