Skip to content

[issue #660] feat: Update generalised error message for all features - #759

Open
SohamPatel46 wants to merge 10 commits into
WordPress:developfrom
SohamPatel46:feature/issue-660
Open

[issue #660] feat: Update generalised error message for all features#759
SohamPatel46 wants to merge 10 commits into
WordPress:developfrom
SohamPatel46:feature/issue-660

Conversation

@SohamPatel46

@SohamPatel46 SohamPatel46 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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?

  1. REST Error Customizer:
    • Registered the rest_post_dispatch filter inside the Connector_Approval experiment class.
    • If a REST request fails with the wpai_connector_not_approved code, 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.").
    • Appends: "The AI connector is currently pending authorization. Please approve the request under Tools > Connector Approvals."
  2. Capability Check Fallback:
    • Updated ensure_text_generation_supported() and ensure_image_generation_supported() in Abstract_Ability.
    • If the remote model fetch requests get blocked by the approvals check during capability check, it now falls back to return wpai_connector_not_approved instead of the generic unsupported_model error.

Use of AI Tools

  • AI assistance: Yes
  • Tool(s) used: Antigravity IDE.
  • Model(s) used: Gemini 3.5 Flash
  • Used for: Suggestion for designing the centralized server-side solution, code refactoring, test case additions. Implementation was reviewed, modified and tested by me.

Testing Instructions

  1. Install the AI plugin and configure an AI provider (e.g., Google Connector), but do not approve the caller under Tools > Connector Approvals yet.
  2. Open a page/post and click Generate Title.
  3. Verify that the notice displays: "Title generation failed. The AI connector is currently pending authorization. Please approve the request under Tools > Connector Approvals."
  4. Click Generate Excerpt (if excerpt generation experiment is active) and verify it displays: "Excerpt generation failed. The AI connector is currently pending authorization. Please approve the request under Tools > Connector Approvals."
  5. Go to Tools > Connector Approvals and approve the connector.
  6. Return to the post editor and verify that title and excerpt generation now succeed without the error.

Screenshots or screencast

Before After
before after
before-2 after-2

Changelog Entry

Fixed - Display a clear, context-aware error notice during Ability execution when the configured AI connector is pending administrator approval.

Added - New feature.
Changed - Existing functionality.
Deprecated - Soon-to-be removed feature.
Removed - Feature.
Fixed - Bug fix.
Security - Vulnerability.
Developer - Development related updates.

Open WordPress Playground Preview

@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: SohamPatel46 <sohampate1@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: riccardodicurti <riccardodicurti@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.79%. Comparing base (9db55ee) to head (3cd5918).

Files with missing lines Patch % Lines
includes/Abstracts/Abstract_Ability.php 92.30% 2 Missing ⚠️
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     
Flag Coverage Δ
unit 75.79% <97.61%> (+0.29%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread includes/Abstracts/Abstract_Ability.php Outdated
@jeffpaul jeffpaul added this to the 1.2.0 milestone Jun 26, 2026
@SohamPatel46
SohamPatel46 requested a review from dkotter June 30, 2026 11:20
@SohamPatel46
SohamPatel46 requested a review from a team July 2, 2026 13:21
/**
* Filters the REST response to customize the error message when a request is blocked by Connector Approval.
*
* @since 1.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These still haven't been updated. I'm not going to flag each one but all of them need updated

* @param \WP_REST_Request $request The REST request.
* @return mixed The modified REST response.
*/
public function customize_rest_error( $response, $server, $request ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

*/
private function get_context_aware_error_message( string $ability_id ): string {
switch ( $ability_id ) {
case 'ai/title-generation':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally we aren't hardcoding all of these here as we'll need to remember to update this anytime a new feature is added. It would be great if this could be more dynamic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In addition to these integration tests, we should add some E2E tests that verify the error messages show as expected

Comment thread includes/Abstracts/Abstract_Ability.php Outdated
* @param string $message The fallback error message.
* @return \WP_Error|null A WP_Error if an unapproved connector is found, null otherwise.
*/
private function maybe_get_unapproved_connector_error( string $message ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this belongs on the Abstract_Ability class? Or if this should be in the connector approval code?

@jeffpaul jeffpaul modified the milestones: 1.2.0, 1.3.0 Jul 13, 2026
@jeffpaul

Copy link
Copy Markdown
Member

@SohamPatel46 I'm seeing lots of test failures here, mind reviewing those to see if any are impacted by the changes in this PR?

@jeffpaul jeffpaul mentioned this pull request Aug 10, 2026
48 tasks
@dkotter dkotter modified the milestones: 1.3.0, 1.4.0 Aug 12, 2026
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.

UX: Ambiguous error message in editor when a provider is blocked by Connector Approvals

3 participants