totorototo / strava

"Lybitos-Strava" is a React Native application consuming Strava RESTFul web services.
MIT License
32 stars 5 forks source link

Error handling propagation issue #69

Open totorototo opened 6 years ago

totorototo commented 6 years ago

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

the problem is:

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! :zambia:

totorototo commented 6 years ago

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 }