question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error Catching not working with suspense true

See original GitHub issue

useSWR catching errors is not working when adding to the options suspense true

The code will never enter the if the statement of the error and the website will carshes and If we remove the suspense true everything will work fine

 const fetcher = url => Axios.get(url, authHeader()).then(res => res.data);
    const url = `${apiUrl}/info/5`;
    const { data, error, isValidating } = useSWR(url, fetcher, , { suspense: true });
    if (error) {
console.log('error');
    }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
koba04commented, Jan 11, 2021

👍 BTW, vercel/swr enables GitHub Discussions, so I think it’s the best place to post a question like this😄 https://github.com/vercel/swr/discussions

1reaction
koba04commented, Jan 11, 2021

@AmmarMohamadIsmaeel You can handle errors differently on each component by creating each ErrorBoundary or passing different props to a single ErrorBoundary.

<ErrorBoundaryA>
  <PageA />
</ErrorBoundaryA>

<ErrorBoundaryB>
  <PageB />
</ErrorBoundaryB>

or

<ErrorBoundary errorType="a">
  <PageA />
</ErrorBoundary>

<ErrorBoundary errorType="b">
  <PageB />
</ErrorBoundary>

Does it make sense?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Catch Your Suspense Errors - chan.dev
Catch Your Suspense Errors. Not every promise resolves. Some are rejected. So, when we use React.Suspense to show loading and loaded states,
Read more >
With React 18 and suspense, how to display specific errors ...
Probably the most tricky part is how to trigger the error to be checked, especially since the code is using async\await . Check...
Read more >
React Suspense Error Handling and Post Requests - YouTube
Learn how to fetch new data, handle errors, and do post request with Suspense in React.
Read more >
Suspense - SWR
SWR is a React Hooks library for data fetching. SWR first returns the data from cache (stale), then sends the fetch request (revalidate),...
Read more >
Error Boundaries - React
To solve this problem for React users, React 16 introduces a new concept of an “error boundary”. Error boundaries are React components that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found