From 444c3ab4d3644c86e2451228baea70569fc42ae1 Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Thu, 22 Aug 2024 00:19:22 +0200 Subject: [PATCH] Automatically throw on CORS error responses (e.g. Cloudflare timeouts) --- .changelog/1513.bugfix.md | 1 + src/index.tsx | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changelog/1513.bugfix.md diff --git a/.changelog/1513.bugfix.md b/.changelog/1513.bugfix.md new file mode 100644 index 000000000..58eb99eee --- /dev/null +++ b/.changelog/1513.bugfix.md @@ -0,0 +1 @@ +Automatically throw on 5xx error responses diff --git a/src/index.tsx b/src/index.tsx index bce9b1e01..056da28d4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -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 }, }, },