-
Notifications
You must be signed in to change notification settings - Fork 20
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
Studio: Output proper message on push error #711
Conversation
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.
Works as expected 👍 However, I think we should make a small tweak to the code. I'll still approve straight away, though, to speed things up
if ( typeof error === 'object' && error !== null && 'error' in error ) { | ||
errorMessage = ( error as { error: string } ).error || errorMessage; | ||
} |
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.
if ( typeof error === 'object' && error !== null && 'error' in error ) { | |
errorMessage = ( error as { error: string } ).error || errorMessage; | |
} | |
if ( typeof error?.error === 'string' && error.error ) { | |
errorMessage = error.error; | |
} |
I did some digging to try and find a better way to identify if error
is of the right type. I couldn't find anything great, but I still think we can improve the current solution slightly.
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.
Thank you for your suggestion, @fredrikekelund. Originally, I had a simpler check in place, but TS was not happy about it. Even though I prefer the suggested change, it still triggers the following error:
Property 'error' does not exist on type '{}'.
Every alternative I have tried so far is quite verbose too. 🤔
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.
Would it make sense to move this logic to a separate function so that instead of redefining the variables, we could rely on early returns?
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.
TS was not happy about it
Seems like I overlooked the TS errors in my suggestion yesterday…
move this logic to a separate function
Yeah, adding a getErrorMessageFromResponse
function, or alternatively, an isDecoratedErrorResponse
function seems like a good idea. It would help clean up this code. Those function names are obviously just suggestions.
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.
Thank you, Wojtek and Fredrik. I have extracted out the logic in the latest commit 9439ade. Feel free to let me know what you think.
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.
Just to note that I have now simplified the logic even further based on Wojtek's suggestion.
Related issues
Proposed Changes
Testing Instructions
public-api.wordpress.com
.npm start
.https://wordpress.com/staging-site/{site-slug}
), initiate a sync from staging to production.Pre-merge Checklist