-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
redux-routine casts anything to an Error object from a rejected promise. #12375
Comments
I'm keen on exploring whether we should throw actual |
This implements a new `ErrorResponse` object that `Object.defineProperties` for all of the properties of the original response object and overrides the `toString` method to maintain Backwards Compatibility. Fixes WordPress#12375.
I opened a PR that fixes this using the approach of throwing actual Another possibility is that we expose a function responseToError( response ) {
throw new ErrorResponse( response );
} API_FETCH( { request } ) {
return triggerApiFetch( request ).catch( responseToError );
}, Though I think this would end up giving us a slightly less useful stack trace. |
In #13315, I have an alternative (or complementary possibly) fix to this which changes how |
@TimothyBJacobs #13315 has been merged which should fix this issue. However, I think it's still up in the air whether apiFetch could serve to be improved or not. So I'll leave it up to you whether you leave this issue and your pull open. I'm kind of on the fence with it. |
Can we update the issue title with whatever it ends up being oriented toward, if kept open to serve a different purpose from what's already been fixed? |
Let's consider this as satisfied by #13315. If further improvements are desired, a new issue should be created. (Commented similarly at #12376 (comment)) |
Sorry, yes the changes in #13315 seem sufficient to me. |
Describe the bug
When an
apiFetch
is yielded from a control, it is impossible to access the response error object because it is cast to anError
object which only accepts strings.To Reproduce
Steps to reproduce the behavior:
Setup a
apiFetch
control. I'm using the definition that GB uses incore-data
.In an action or resolver, yield an
apiFetch
that server will return a non 200 error for.e is an
Error
object with the message[object Object]
.This seems to happen because
castError
inredux-routine
will cast anything rejected from a promise to anError
object which only supportsstring
messages.See related Slack discussion: https://wordpress.slack.com/archives/C02QB2JS7/p1543350222369000
Expected behavior
To be able to access the original REST Response body.
Workarounds
Change the control definition to:
This would then require parsing the JSON again in any consuming code.
The text was updated successfully, but these errors were encountered: