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

Shows an error message if the server returned invalid json during a Sync #2677

Merged

Conversation

dsawardekar
Copy link
Contributor

Description of the Change

This PR improves error handling of the Dashboard Sync by displaying an error message when the admin-ajax calls return invalid JSON data.

This is what the Sync UI looks like without this fix on the develop branch, when the server returns an invalid JSON response.

sync_json_develop

And this is what the Sync UI looks on this feature branch with the same invalid JSON response.

sync_invalid_json

To test this PR I created an mu-plugin with the following code. This can also be seen by introducing other output into admin-ajax calls like PHP Warnings, incorrectly output styles, etc.

<?php

add_action( 'admin_init', function() {
	if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
		return; 
	}

	throw new Exception( 'Exception during Admin AJAX' );
} );

Closes #2301

Possible Drawbacks

NA

Verification Process

  • Create an mu-plugin and copy-paste the above admin_init code into it.
  • Run the Sync from the Dashboard
  • You should see an error message that the Sync failed.
  • The logs tab should also show an invalid json error message.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Fixed: Display and error message if syncing failed due to invalid JSON response from the server.

Credits

Props @dsawardekar

@felipeelia felipeelia added this to the 4.1.0 milestone Mar 24, 2022
@felipeelia felipeelia self-assigned this Mar 24, 2022
@felipeelia felipeelia merged commit 237b4ad into develop Mar 25, 2022
@felipeelia felipeelia deleted the feature/show-error-state-on-invalid-json-response branch March 25, 2022 13:46
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.

Throw a console error if admin-ajax data from indexing is malformed
2 participants