Skip to content

Commit

Permalink
add error handling to async case
Browse files Browse the repository at this point in the history
  • Loading branch information
vsseixaso committed Jun 3, 2024
1 parent e3494eb commit a2569ec
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/HttpClient/middlewares/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,19 @@ 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},
responseEncoding,
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({
Expand Down

0 comments on commit a2569ec

Please sign in to comment.