Improve error messaging for AI Assistant when WordPress.com connection is missing#46350
Improve error messaging for AI Assistant when WordPress.com connection is missing#46350
Conversation
| if ( 'missing_token' === $response->get_error_code() ) { | ||
| return new WP_Error( | ||
| 'missing_token', | ||
| __( 'Your account must be connected to WordPress.com to generate AI images. Please connect your account from the Jetpack settings screen to proceed.', 'jetpack' ), |
There was a problem hiding this comment.
@copilot : Can we refactor this repetitive error message into a constant?
There was a problem hiding this comment.
Refactored into constants in commit ed97f74. Added three constants: ERROR_MSG_WPCOM_CONNECTION_REQUIRED_FOR_AI_IMAGES, ERROR_MSG_WPCOM_CONNECTION_REQUIRED_FOR_AI_CONTENT, and ERROR_MSG_WPCOM_CONNECTION_REQUIRED_FOR_AI_ASSISTANCE.
There was a problem hiding this comment.
@copilot This causes an error:
The $text parameter must be a single text string literal. Found: self::ERROR_MSG_WPCOM_CONNECTION_REQUIRED_FOR_AI_IMAGESPHP_CodeSniffer(WordPress.WP.I18n.NonSingularStringLiteralText)
The entire __() call must be refactored.
…n is missing Co-authored-by: annezazu <26996883+annezazu@users.noreply.github.com>
Co-authored-by: saroshaga <14042477+saroshaga@users.noreply.github.com>
c1b4aa5 to
dfd1eca
Compare
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 🔴 Action required: Please include detailed testing steps, explaining how to test your change, like so: 🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so: Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
Full summary · PHP report · JS report Coverage check overridden by
I don't care about code coverage for this PR
|
|
Testing by connecting Jetpack, adding an AI Assistant block and then disconnecting, the message stays the same: The error messages are defined on the React side. For streaming responses like the AI Assistant block, they are on the |
Plan to Improve UI Messaging for AI Assistant Connection Errors
class-wpcom-rest-api-v2-endpoint-ai.phpJetpack_AI_Helper::get_status_permission_checkget_dalle_generation()methodget_gpt_completion()methodmissing_tokenandunavailable_site_idget_dalle_generation()to detect connection errors and return improved messageget_gpt_completion()to detect connection errors and return improved messageChanges Summary
Modified
/projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.phpto improve error messages when users try to use AI Assistant without WordPress.com connection:Constants Added:
ERROR_MSG_WPCOM_CONNECTION_REQUIRED_FOR_AI_IMAGESERROR_MSG_WPCOM_CONNECTION_REQUIRED_FOR_AI_CONTENTERROR_MSG_WPCOM_CONNECTION_REQUIRED_FOR_AI_ASSISTANCEFor Image Generation (
get_dalle_generation):unavailable_site_idandmissing_tokenerrorsFor Text Completion (
get_gpt_completion):unavailable_site_idandmissing_tokenerrorsThe changes eliminate code duplication by using class constants, maintain backward compatibility by keeping the same error codes, and only improve the error message text to be more user-friendly and actionable.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.