appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.89k stars 467 forks source link

Catch 401 errors without throwing error when auth is not valid anymore #1590

Open rap2hpoutre opened 3 years ago

rap2hpoutre commented 3 years ago

When a search fails and returns 401 (let's say because the session is not valid anymore), Reactive Search throws an error. I would love to catch it to not trigger an error, since it just means the connection is lost. The problem in throwing an error is that it adds some mess the console and the bug trackers (eg: Sentry). For instance, I would love a clean way to catch the error then redirect the user to a auth. onError on components is too late since the error is already thrown.

I'm using v3.14.0 (React project)

bietkul commented 3 years ago

It seems a good idea. We can add onError prop in the ReactiveBase to catch errors.

DanielHabenicht commented 3 years ago

Love it and was about to create another Issue for it! I also think it would be a great Idea to make this for all Errors that might happen, not just the network requests.

rap2hpoutre commented 3 years ago

Any news about this issue?

siddharthlatest commented 3 years ago

Thanks for bringing attention to this. We would like to support this use-case. Also in case someone wants to contribute sooner, happy to provide guidance on how to do this.

rap2hpoutre commented 2 years ago

@siddharthlatest OK, thank you. I don't know where to start, but I would be glad to tackle this issue. I checked ReactiveBase in web but I did not found where the query is actually done nor where I can catch errors (I see a componentDidCatch that does not seem to be triggered). Could you give me guidance on how I should start?

bietkul commented 2 years ago

@rap2hpoutre The existing componentDidCatch would not get invoked on network calls error. The best way to catch the network requests errors is to use the StateProvider component. Check this example https://codesandbox.io/s/optimistic-euclid-2tbm7?file=/src/index.js

bietkul commented 2 years ago

@rap2hpoutre As per your use-case, you want to handle the error before ReactiveSearch processes it. For e.g if ReactiveList was showing some results and next request caused some error then it should not clear the results.