-
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
[RNMobile] Prevent unhandled promise rejection warning related to canUser resolver #39144
Conversation
Size Change: -195 B (0%) Total Size: 1.15 MB
ℹ️ View Unchanged
|
This patch certainly avoids the crash, but do we know why there is no |
Oh, sorry for not providing the entire context. In the native version, all the network logic is managed by the WordPress app. For succeeded network requests, we only get the result object of the response hence, we don't receive any properties of the HTTP request like the headers. However, we do receive it on failed requests, mostly in order to determine the error type via the HTTP status code. As an example, let me share some references to the iOS native code to expand the explanation:
I'd agree that it would be quite helpful to also receive the HTTP response object, as it would prevent issues like the one addressed by this PR. But I'm afraid that until we refactor the network logic, in the native version we have this limitation. In fact, I also bumped into this problem on other issues like wordpress-mobile/gutenberg-mobile#2661, related to the unbounded queries functionality from fetch-all-middleware, which is not supported due to this same problem.
Right, the |
That happens in the web version, too, we get only the parsed response JSON body and nothing else. However, when the apiFetch( { path, method: 'OPTIONS', parse: false } ) This means that we want to get the raw
Yeah if the mobile app is content with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK for now, until a deeper fix in React Native apiFetch
is done 👍
@@ -292,7 +292,7 @@ export const canUser = ( action, resource, id ) => async ( { dispatch } ) => { | |||
return; | |||
} | |||
|
|||
const allowHeader = response.headers.get( 'allow' ); | |||
const allowHeader = response.headers?.get( 'allow' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment explaining that the ?.
operator needs to be used because the React Native apiFetch
doesn't return the expected result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment related to this in b268726.
That's interesting, it would be great if we could match the same behavior in the native version, and totally agree that the network logic should respect that 👍 .
Yep, I know it's not ideal to have
I totally agree, I'll open a ticket as a follow-up of this and highlight the importance of providing the same behavior, in order to prevent future issues. Thanks @jsnajdr for taking a look at the PR 🙇, I'll add the comment you mentioned in #39144 (comment), and then we could merge the fix. |
In relation to this comment, I'd like to share that I opened #39182. |
Description
As outlined in #39143 (comment), the issue has been addressed by using the optional chaining operator when retrieving the headers from the response.
Testing Instructions
Screenshots
N/A
Types of changes
Bug fix
Checklist:
*.native.js
files for terms that need renaming or removal).