Skip to content

Commit

Permalink
feat: improve error handling (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
aui authored May 14, 2024
1 parent 40db89b commit 453e7ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-points-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web-widget/shared-cache": patch
---

Improve error handling.
11 changes: 6 additions & 5 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,12 @@ export class SharedCache implements Cache {
try {
revalidationResponse = await fetch(revalidationRequest);
} catch (error) {
if (resolveCacheItem.policy.useStaleIfError()) {
revalidationResponse = resolveCacheItem.response;
} else {
throw error;
}
revalidationResponse = new Response(
error instanceof Error ? error.message : 'Internal Server Error',
{
status: 500,
}
);
}

const { modified, policy: revalidatedPolicy } =
Expand Down

0 comments on commit 453e7ee

Please sign in to comment.