Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't catch thrown 'FLOW_CANCELED' anywhere #2790

Closed
DMS40 opened this issue Feb 5, 2021 · 5 comments
Closed

Can't catch thrown 'FLOW_CANCELED' anywhere #2790

DMS40 opened this issue Feb 5, 2021 · 5 comments
Labels
📖 documentation 🍗 enhancement 🎁 mobx Issue or PR related to mobx package

Comments

@DMS40
Copy link

DMS40 commented Feb 5, 2021

Intended outcome:

This issue came from here

When flow function's cancel() fired, Can't catch thrown 'FLOW_CANCELED' anywhere

image

Actual outcome:

Can catch the flow function's cancel() fired, for don't want to show throw error message

This also interferes with the integrated test. like for react-testing-library

How to reproduce the issue:

https://codesandbox.io/s/magical-hugle-qc0d1?file=/src/App.js

Versions
mobx : 6.1.5
mobx-react-lite : 3.2.0
react : 17.0.1
react-dom : 17.0.1
react-scripts : 4.0.0

@DMS40 DMS40 added the 🐛 bug label Feb 5, 2021
@danielkcz danielkcz added 🎁 mobx Issue or PR related to mobx package 👓 needs investigation labels Feb 5, 2021
@urugator
Copy link
Collaborator

urugator commented Feb 5, 2021

useEffect(() => {
    const fetch = flowResult(store.flowAction());
    // ---
    fetch.catch(error => console.log("CATCHED"));
    // ---
    return () => fetch.cancel();
  }, [store]);

@iChenLei
Copy link
Member

iChenLei commented Feb 6, 2021

issue Errors handing for effect callbacks
testing-library/react-hooks-testing-library#308

I think we should add usage(code example) to official document.
👉 https://mobx.js.org/actions.html#cancelling-flows-

urugtor's code snippt is a great solution.

2021-02-06 20 33 16

@DMS40
Copy link
Author

DMS40 commented Feb 6, 2021

Oops! It's my mistake not to try that way. Thank you @urugator

I thought it should be handled inside the flow method!

I tried it on the actual product and it worked perfectly as I wanted.

@iChenLei
Should I close this issue? Or will you close it after considering what you were talking about?

Thank you for your time everyone!

@iChenLei
Copy link
Member

iChenLei commented Feb 6, 2021

https://mobx.js.org/actions.html#cancelling-flows-

@DMS40 please keep it until we get a unanimous view for Do we need mention this case in official doc , Thanks
Better doc , Better development experience 😄 @mweststrate Any suggestion ?

@mweststrate
Copy link
Member

@iChenLei yeah it is probably good to mention that the promise returned from the flow will reject and can be catched. You can't catch it inside the flow itself, but as mentioned the finalization block will run so could be used to detect it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📖 documentation 🍗 enhancement 🎁 mobx Issue or PR related to mobx package
Projects
None yet
Development

No branches or pull requests

5 participants