GithubHelp home page GithubHelp logo

adding an onError prop ? about urql HOT 5 CLOSED

urql-graphql avatar urql-graphql commented on May 21, 2024 1
adding an onError prop ?

from urql.

Comments (5)

morajabi avatar morajabi commented on May 21, 2024

That one which is directly on the client makes more sense to me as for reporting to Sentry.

Although most of the GraphQL errors are to be handled by the app in the UI. You should catch the others (errors or bugs) in the server side (e.g. Apollo Server) and only pass the errors which are for the users to the client.

The way I might be handling this is to use ConnectHOC and check for error in the componentWillRecieveProps which is not the best practice, especially now that it is deprecated I should use the new hook.

from urql.

shrynx avatar shrynx commented on May 21, 2024

@morajabi i want to handle error in component but also want to have associated side effects for the corresponding error. For eg, if the page listing todo's has error, then push pack to home page or maybe 500 page.
And yes, errors like these should be handled on server-side (in an ideal world), but there are times, when server side has uncaught bugs and i want to gracefully handle them on ui.

Currently i am using getDerivedStateFromProps (componentWillRecieveProps has been / is getting depreciated) to check in the child component of Query if there was error or not, but for this i have to always use a class component as a child of query.
The other approach is to throw an error and catching it in componentDidCatch, enabling me to use stateless components to render result of Query.

from urql.

morajabi avatar morajabi commented on May 21, 2024

I'm not pointing at Redux, as I didn't mention and don't use Redux. Urql exports a ConnectHOC which is a HoC.

I said handling uncought errors with Sentry is supposed to be done on the server side. So you just need to show an error screen in the UI. So you can gracefully handle them in UI, I think you're not quite used to the render props pattern yet, maybe.

<Connect> 
{({ error }) => {
  if (error) {
    return <ErrorScreen error={error} />
  }
  // ...
}}
</Connect>

This is quite like how React apps should be architectured.

Throwing an error makes total sense as well, and I think it is there for situations like this, but most of the time it is not necessary.

from urql.

shrynx avatar shrynx commented on May 21, 2024

@morajabi ahh sorry i miss read about Connect 😅 . my problem is I don't want to display error, i want to change route (for eg).
Also backend team doesn't use sentry and i do want to use it for failing queries.

PS: Don't mind but, I don't feel there is a single way of how react apps should be architectured, in my app i would like to re route user on error and see nothing wrong in that

from urql.

shrynx avatar shrynx commented on May 21, 2024

i am sticking to throwing errors and catching the , thus closing the issue

from urql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.