diff --git a/docs/framework/react/overview.md b/docs/framework/react/overview.md index 6c9a3f0dacd..aeb41171797 100644 --- a/docs/framework/react/overview.md +++ b/docs/framework/react/overview.md @@ -68,10 +68,17 @@ export default function App() { function Example() { const { isPending, error, data } = useQuery({ queryKey: ['repoData'], - queryFn: () => - fetch('https://api.github.com/repos/TanStack/query').then((res) => - res.json(), - ), + queryFn: async () => { + const response = await fetch( + 'https://api.github.com/repos/TanStack/query', + ) + + if (!response.ok) { + throw new Error(`Request failed with status ${response.status}`) + } + + return response.json() + }, }) if (isPending) return 'Loading...' diff --git a/examples/react/simple/src/index.tsx b/examples/react/simple/src/index.tsx index ba0332f5e6d..359393e1ffb 100644 --- a/examples/react/simple/src/index.tsx +++ b/examples/react/simple/src/index.tsx @@ -25,7 +25,12 @@ function Example() { const response = await fetch( 'https://api.github.com/repos/TanStack/query', ) - return await response.json() + + if (!response.ok) { + throw new Error(`Request failed with status ${response.status}`) + } + + return response.json() }, })