Skip to content

Commit

Permalink
Merge pull request #1513 from oasisprotocol/lw/cors-errors
Browse files Browse the repository at this point in the history
Automatically throw on CORS error responses (e.g. Cloudflare timeouts)
  • Loading branch information
lukaw3d authored Aug 22, 2024
2 parents c56583e + 444c3ab commit 35d0f9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/1513.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Automatically throw on 5xx error responses
9 changes: 8 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const queryClient = new QueryClient({
useErrorBoundary: (error: any) => {
// Automatically throw on 5xx errors. Components that want to handle
// errors should set `useErrorBoundary: false` in their queries.
return error.response?.status >= 500
if (error.response?.status >= 500) return true

// https://nexus.oasis.io/v1/sapphire/events?offset=0&limit=10&type=evm.log&evm_log_signature=ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef&rel=oasis1qpdgv5nv2dhxp4q897cgag6kgnm9qs0dccwnckuu
// threw 524 error after 100 seconds but didn't return status code to javascript. It's because Nexus didn't
// respond quickly enough, so Cloudflare canceled with timeout, but Cloudflare doesn't add Nexus' CORS headers.
if (!error.response && error.code === 'ERR_NETWORK') return true

return false
},
},
},
Expand Down

0 comments on commit 35d0f9a

Please sign in to comment.