Skip to content
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

Merged
merged 4 commits into from
Dec 4, 2024

Conversation

ivan-ottinger
Copy link
Contributor

@ivan-ottinger ivan-ottinger commented Dec 2, 2024

Related issues

Proposed Changes

  • output relevant message on push error

Markup on 2024-12-02 at 15:43:13

Testing Instructions

  1. Apply the backend diff (D167588-code) to your sandbox and sandbox public-api.wordpress.com.
  2. Check out this PR and build the app with npm start.
  3. Navigate to the Sync tab and make sure you have a WPCOM site with its staging site connected.
  4. While at the staging site settings tab (https://wordpress.com/staging-site/{site-slug}), initiate a sync from staging to production.
  5. Head back to the Sync tab in Studio and try to initiate a push operation.
  6. After some time, a dialog with relevant error message should display (as can be seen in the screenshot above).

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@ivan-ottinger ivan-ottinger self-assigned this Dec 2, 2024
@ivan-ottinger ivan-ottinger requested a review from a team December 2, 2024 15:19
Copy link
Contributor

@fredrikekelund fredrikekelund left a 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

Comment on lines 133 to 135
if ( typeof error === 'object' && error !== null && 'error' in error ) {
errorMessage = ( error as { error: string } ).error || errorMessage;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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. 🤔

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

@ivan-ottinger ivan-ottinger Dec 4, 2024

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.

Copy link
Contributor Author

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.

@ivan-ottinger ivan-ottinger merged commit 4080ae8 into trunk Dec 4, 2024
6 checks passed
@ivan-ottinger ivan-ottinger deleted the update/push-error-handling branch December 4, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants