From a2569ecde37263a99ca53cf46c05d6bc086cf893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Seixas?= Date: Mon, 3 Jun 2024 17:52:29 -0300 Subject: [PATCH] add error handling to async case --- src/HttpClient/middlewares/cache.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/HttpClient/middlewares/cache.ts b/src/HttpClient/middlewares/cache.ts index 93771649..a63bbf57 100644 --- a/src/HttpClient/middlewares/cache.ts +++ b/src/HttpClient/middlewares/cache.ts @@ -224,8 +224,8 @@ export const cacheMiddleware = ({ type, storage, asyncSet }: CacheOptions) => { const cacheWriteSpan = createCacheSpan(cacheType, 'write', tracer, span) try { - const storageSet = () => - storage.set(setKey, { + const storageSet = async () => + await storage.set(setKey, { etag, expiration, response: {data: cacheableData, headers, status}, @@ -233,7 +233,10 @@ export const cacheMiddleware = ({ type, storage, asyncSet }: CacheOptions) => { responseType, }) if (asyncSet) { - storageSet() + storageSet().catch(error => { + ErrorReport.create({ originalError: error }).injectOnSpan(cacheWriteSpan); + logger?.warn({ message: 'Error writing to the HttpClient cache asynchronously', error }); + }) } else { await storageSet() span?.log({