[issue #660] feat: Update generalised error message for all features - #759
[issue #660] feat: Update generalised error message for all features#759SohamPatel46 wants to merge 10 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #759 +/- ##
=============================================
+ Coverage 75.50% 75.79% +0.29%
- Complexity 2086 2117 +31
=============================================
Files 99 99
Lines 8626 8710 +84
=============================================
+ Hits 6513 6602 +89
+ Misses 2113 2108 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| * @param \WP_REST_Request $request The REST request. | ||
| * @return mixed The modified REST response. | ||
| */ | ||
| public function customize_rest_error( $response, $server, $request ) { |
There was a problem hiding this comment.
So I don't necessarily have a better approach off the top of my head but not sure I love us hooking into rest_post_dispatch and then running all of this functionality. Seems this is likely to impact things we don't want to impact (slowing down other, non-AI requests as an example). Wondering if there's a better approach to handle this?
There was a problem hiding this comment.
In addition to these integration tests, we should add some E2E tests that verify the error messages show as expected
|
@SohamPatel46 I'm seeing lots of test failures here, mind reviewing those to see if any are impacted by the changes in this PR? |
What?
Closes #660
Implements a centralized, context-aware error message mapping in the WordPress REST API when AI requests (e.g. "Generate Title", "Generate Excerpt") are blocked by the Connector Approvals feature.
Why?
Previously, when the Connector Approvals feature blocked the caller (
wp-ai), the user was shown a generic error notice: "Title generation failed. Please ensure you have a connected provider that supports text generation." This led users to believe that their API keys or connected providers were broken when the feature was actually just awaiting approval in the WordPress admin panel.Using a centralized server-side approach via a REST dispatch filter ensures that all features display clean, translated, and context-aware instructions explaining how to authorize the connector under
Tools > Connector Approvals, without duplicating approval-checking code across individual feature controllers or frontend JS files.How?
rest_post_dispatchfilter inside the Connector_Approval experiment class.wpai_connector_not_approvedcode, it intercepts the error, parses the Ability ID from the route path, and maps it to a context-aware prefix (e.g. "Title generation failed.", "Excerpt generation failed.").ensure_text_generation_supported()andensure_image_generation_supported()in Abstract_Ability.wpai_connector_not_approvedinstead of the genericunsupported_modelerror.Use of AI Tools
Testing Instructions
Screenshots or screencast
Changelog Entry
Fixed - Display a clear, context-aware error notice during Ability execution when the configured AI connector is pending administrator approval.