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

Add better error handling for manual scanning of alt text or image tags #231

Merged
merged 7 commits into from
Oct 20, 2020

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented Oct 16, 2020

Description of the Change

Make sure our requests to generate alt text or image tags return a WP_Error object if something goes wrong. Currently we are returning those in a few instances but not in every instance.

In our javascript that makes these requests, if the response fails, check to see if we have error details and if so, show that error message. If we don't have error details, output a default error message. Also, make sure the spinner is removed so it doesn't appear like things are still processing.

Alternate Designs

None

Benefits

If a request fails, we provide feedback to the user about what went wrong.

Possible Drawbacks

None

Verification Process

  1. Setup the plugin
  2. Disable either the Automatically Caption Images or Automatically Tag Images options (or both)
  3. Select an existing image in the media library or upload a new one
  4. With the image selected, in the media modal that opens, click the button that corresponds to the setting disabled above. Ensure an error message is shown and the spinner goes away

Screen Shot 2020-10-19 at 12 32 37 PM

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.

Applicable Issues

#230

…rror objects if anything goes wrong. Modify our JS that makes these API requests to ensure if something goes wrong, we output that error message to the user and remove the spinner.
@jeffpaul jeffpaul added this to the 1.6.0 milestone Oct 16, 2020
@jeffpaul jeffpaul added the type:bug Something isn't working. label Oct 16, 2020
Copy link
Contributor

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

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

I just have a question about retrying scanning, otherwise, this is looking good to me!

src/js/media.js Outdated
Comment on lines 32 to 40
const errorObj = get( error, 'responseJSON', {
code: 'unknown_error',
message: __( 'An unknown error occurred.', 'classifai' ),
} );
spinner.style.display = 'none';
spinner.classList.remove( 'is-active' );
button.textContent = __( 'Error', 'classifai' );
errorContainer.style.display = 'inline-block';
errorContainer.textContent = errorObj.message;
Copy link
Contributor

Choose a reason for hiding this comment

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

How do users retry scanning after failing (due to network issue for example)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dinhtungdu Thanks for the review! Just pushed a fix for this, so if an error happens, we make sure the button is no longer disabled, so it can be clicked again

Copy link
Contributor

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@jeffpaul jeffpaul merged commit 212e6da into develop Oct 20, 2020
@dkotter dkotter deleted the fix/error-handling branch October 20, 2020 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When manually scanning for alt text or tags, if request fails, spinner never goes away
3 participants