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

Error handling propagation issue #69

Open
totorototo opened this issue Oct 26, 2017 · 1 comment
Open

Error handling propagation issue #69

totorototo opened this issue Oct 26, 2017 · 1 comment

Comments

@totorototo
Copy link
Owner

there is something fishy in the chain saga, service, helper.

  • services are in charge of:

    • formatting data to be passed to an helper,
    • calling helpers,
    • formatting returned data from that helper.
  • helpers are generally based promise,

  • this is exactly the same for services.

the problem is:

  • what if an helper reject a promise?
  • how is that handled in services?

PS:
Be aware of what is the return value of .then(): resolve or failure.
Considering the returned value of .then() in both case, we have done something wrong here!
🇿🇲

@totorototo
Copy link
Owner Author

totorototo commented Nov 13, 2017

As we discussed, something should be done using fp (Monads, ...).
see:
https://medium.com/javascript-scene/javascript-monads-made-simple-7856be57bfe8
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html

{
const composeM = chainMethod => (...ms) => (
ms.reduce((f, g) => x => g(x)chainMethod)
);
const composePromises = composeM('then');
const label = 'API call composition';
// a => Promise(b)
const getUserById = id => id === 3 ?
Promise.resolve({ name: 'Kurt', role: 'Author' }) :
undefined
;
// b => Promise(c)
const hasPermission = ({ role }) => (
Promise.resolve(role === 'Author')
);
// Compose the functions (this works!)
const authUser = composePromises(hasPermission, getUserById);
authUser(3).then(trace(label)); // true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants