-
Notifications
You must be signed in to change notification settings - Fork 195
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 propagation #163
Comments
Hi @niccolomeloni, This is a great question. Can you take a look at https://github.com/agraboso/redux-api-middleware#lifecycle and let me know if that helps make sense of the middleware flow. The
I'm curious how we can make this more clear / useful 🤔 |
Hi @nason, i read the link you have shared and the source code of middleware. In order to accomplish error propagation i thing that it could be a solution in For example, instead of try {
// Make the API call
var res = await fetch(endpoint, {
...options,
method,
body,
credentials,
headers: headers || {}
});
} catch (e) {
// The request was malformed, or there was a network error
return next(
await actionWith(
{
...requestType,
payload: new RequestError(e.message),
error: true
},
[action, getState()]
)
);
} middleware could perform try {
// Make the API call
var res = await fetch(endpoint, {
...options,
method,
body,
credentials,
headers: headers || {}
});
} catch (e) {
var err = new RequestError(e.message);
next(
await actionWith(
{
...requestType,
payload: err,
error: true
},
[action, getState()]
)
);
throw err; // return Promise.reject(err);
} This pattern could be applied for each dispatch(rsaa_action())
.then(response => /* ...A... */)
.catch(err => /* ...B...*/) Let me know what do you think about it. My best, |
Ah, gotcha! I think there's certainly value in doing something like this. The first things that come to my mind are: how would this change affect existing users, what would a migration plan look like, and so on. I'm swamped for the rest of this week, but I'll think about this some more and chime back in soon. |
Hi,
i'd like to ask you if is expected on next future to have error propagation (when REQUEST fail or FAILURE). At the moment i'm using following pattern:
but i think it could be better if the error were propagated in order to use normal pattern:
Please, could you let me know something about?
Did i fell in a concept mistake?
My best,
Niccolò
The text was updated successfully, but these errors were encountered: