Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically throw on CORS error responses (e.g. Cloudflare timeouts) #1513

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading