-
Notifications
You must be signed in to change notification settings - Fork 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
E2E Framework: fix empty array check in RestAPIClient. #74741
Conversation
- fix empty array check
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
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.
Thanks! There is actually one other example I forgot to mention:
if ( response.errors === [] ) { |
Could you also add a fix for that?
- fix another instance of comparison
Done - thanks for the heads up! |
@@ -360,7 +360,7 @@ export class RestAPIClient { | |||
); | |||
} | |||
|
|||
if ( response.errors === [] ) { | |||
if ( response.errors.length === 0 ) { | |||
console.log( response ); | |||
throw new Error( `Failed to create invite: ${ response.errors }` ); |
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 think we need to check if there are errors here!
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.
Right, I didn't read the rest of the lines before making the change, but am a little confused at this logic now - I think we handled the error scenario in Line 357-360, so not sure why we're checking another error here.
Going to play with the console for a bit to see what is up.
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.
Ah okay, I should have written some comments because it isn't straightforward at first glance.
The first hasOwnProperty
is checking for API errors.
The second error
check is checking for errors relating to the invite itself.
I've added comment, fixed the logic for the if
clause and added a helpful console.error
level output.
- fix if logic. - add output. - add comments.
for ( const err of response.errors ) { | ||
console.error( `${ err.code }: ${ err.message }` ); | ||
} | ||
throw new Error( `Failed to create invite due to ${ response.errors.length } errors.` ); |
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.
Nice change, this makes a lot more sense to me 👍
throw new Error( `Failed to create invite: ${ response.errors }` ); | ||
// This handles "errors" relating to the invite itself and can be an array. | ||
// For instance, if a user tries to invite itself, or invite an already added user. | ||
if ( response.errors.length !== 0 ) { |
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.
nitpicky review comment alert :D
I kinda prefer > 0
to !== 0
, but it doesn't make a practical difference. Or, you can even just do if ( response.errors.length )
for a quick truthy check
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.
True, I like that.
- truthy check
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.
Nice catch on the empty array check!
Related to #74479 (comment).
Proposed Changes
This PR fixes the empty array check introduced in #74479.
Testing Instructions
Pre-merge Checklist