Repository navigation
[issue #660] feat: Update generalised error message for all features - #759
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #759 +/- ##
=============================================
+ Coverage 84.26% 84.28% +0.02%
- Complexity 3723 3728 +5
=============================================
Files 148 148
Lines 14099 14118 +19
=============================================
+ Hits 11881 11900 +19
Misses 2218 2218
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? |
|
@SohamPatel46 are you able to make updates here or is it best if another contributor helps out with those failing tests? |
… improve error handling
…se that message. Ensure the error message is different depending on the user that is being shown it
dkotter
left a comment
There was a problem hiding this comment.
Note I've simplified the approach here quite a bit, where we keep track of when a request is blocked on the HTTP Guard side and then output that error message later if needed. This avoids a lot of the over complexity here.
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.