TanStackT
TanStack11mo ago
2 replies
popular-magenta

How to Handle notFound() Globally Instead of Checking 404 in Each Loader?

Instead of checking for a 404 status and throwing the notFound() function in each loader separately, can I handle it in one place? For example, in the onError handler of React Query’s QueryCache or in an Axios response interceptor?

I’m trying to implement this as shown in the screenshots, but I’m still encountering an error, as you can see in the screenshots.
Screenshot_2025-02-27_at_00.49.26.png
Screenshot_2025-02-27_at_00.56.44.png
Screenshot_2025-02-27_at_00.59.46.png
Was this page helpful?