SvelteStack / svelte-query

Performant and powerful remote data synchronization for Svelte
https://sveltequery.vercel.app
MIT License
822 stars 30 forks source link

Queries always maked as successful even when error occured #16

Closed xstevenyung closed 3 years ago

xstevenyung commented 3 years ago

Hello,

Thanks a lot for the project and the work put into it, really appreciate having a port of react-query in the Svelte ecosystem!

I notice recently trying to implement error handling logic that queries never really "fail", here an example based on the simple example: https://codesandbox.io/s/optimistic-lumiere-j08we?file=/src/Simple.svelte:0-65

As you can see, I'm hitting a random URL on GitHub which will return a 404 but even when the query fails, $queryResult.error is null.

I also tried on a blank Svelte project and the same issue occurs.

I'm going to investigate a little more in the project to figure where exactly the problem lies.

Thanks again for your work

amen-souissi commented 3 years ago

Hello, Thanks a lot :) To determine a query has errored, the query function must throw. Any error that is thrown in the query function will be persisted on the error state of the query. docs: https://sveltequery.vercel.app/guides/query-functions#handling-and-throwing-errors

example: https://codesandbox.io/s/eager-hawking-ykdml?file=/src/Simple.svelte

Thanks

xstevenyung commented 3 years ago

Oops my bad, I totally forgot that fetch doesn't throw errors on failed request by default!

Thanks a lot for the quick response !