Skip to content

Commit a2569ec

Browse files
committed
add error handling to async case
1 parent e3494eb commit a2569ec

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/HttpClient/middlewares/cache.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,19 @@ export const cacheMiddleware = ({ type, storage, asyncSet }: CacheOptions) => {
224224

225225
const cacheWriteSpan = createCacheSpan(cacheType, 'write', tracer, span)
226226
try {
227-
const storageSet = () =>
228-
storage.set(setKey, {
227+
const storageSet = async () =>
228+
await storage.set(setKey, {
229229
etag,
230230
expiration,
231231
response: {data: cacheableData, headers, status},
232232
responseEncoding,
233233
responseType,
234234
})
235235
if (asyncSet) {
236-
storageSet()
236+
storageSet().catch(error => {
237+
ErrorReport.create({ originalError: error }).injectOnSpan(cacheWriteSpan);
238+
logger?.warn({ message: 'Error writing to the HttpClient cache asynchronously', error });
239+
})
237240
} else {
238241
await storageSet()
239242
span?.log({

0 commit comments

Comments
 (0)