@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-shared",
3
- "version": "2.170.13",
3
+ "version": "2.170.21",
4
4
  "description": "ProteinPaint code that is shared between server and client-side workspaces",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -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).then(async r => {
227
- const response = await processResponse(r)
228
- if (!r.ok) {
229
- console.trace(response)
230
- throw (
231
- 'memFetch error ' +
232
- r.status +
233
- ': ' +
234
- (typeof response == 'object' ? response.message || response.error : response)
235
- )
236
- }
237
- // replace the cached promise result with the actual data,
238
- // since persisting a cached promise for a long time is likely not best practice
239
- dataCache.set(dataKey, { response: deepFreeze(response), exp: Date.now() + cacheLifetime })
240
- return response
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) delete dataCache.delete(dataKey)
254
+ if (dataCache.get(dataKey) instanceof Promise) dataCache.delete(dataKey)
250
255
  throw e
251
256
  }
252
257
  }