Skip to content

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

Merged
dkotter merged 19 commits into
WordPress:developfrom
SohamPatel46:feature/issue-660
Oct 22, 2026
Merged

dkotter merged 19 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.

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.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@codecov

codecov Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.28%. Comparing base (63799d4) to head (814f662).

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              
Flag Coverage Δ
unit 84.28% <100.00%> (+0.02%) ⬆️

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
Comment thread includes/Experiments/Connector_Approval/Connector_Approval.php Outdated
* @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?

Comment thread includes/Experiments/Connector_Approval/Connector_Approval.php Outdated

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
@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 done
@dkotter dkotter modified the milestones: 1.3.0, 1.4.0 Aug 12, 2026
@dkotter dkotter modified the milestones: 1.4.0, Future Release Sep 3, 2026
@jeffpaul

Copy link
Copy Markdown
Member

@SohamPatel46 are you able to make updates here or is it best if another contributor helps out with those failing tests?

@jeffpaul jeffpaul modified the milestones: Future Release, 1.6.0 Sep 17, 2026
@dkotter dkotter modified the milestones: 1.6.0, 1.5.0 Oct 22, 2026

@dkotter dkotter left a comment

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.

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.

@dkotter
dkotter merged commit c19113b into WordPress:develop Oct 22, 2026
36 checks passed
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