Skip to content

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

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

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

Conversation

@SohamPatel46

@SohamPatel46 SohamPatel46 commented Jun 22, 2026

Copy link
Copy Markdown

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: 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
/**
* Checks if any configured connector is unapproved and returns a corresponding WP_Error if so.
*
* @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.

All @since statements need to be set to x.x.x

@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
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