Skip to content

Show specific backend error description on AI provider save (#5028)#1347

Open
Tharsanan1 wants to merge 5 commits into
wso2:mainfrom
Tharsanan1:fix/issue-5028
Open

Show specific backend error description on AI provider save (#5028)#1347
Tharsanan1 wants to merge 5 commits into
wso2:mainfrom
Tharsanan1:fix/issue-5028

Conversation

@Tharsanan1
Copy link
Copy Markdown
Contributor

Issue

Fixes wso2/api-manager#5028

When saving an AI service provider with an invalid metadata identifier, the admin portal displayed a generic error message instead of the specific validation error returned by the backend (e.g., "Invalid JSONPath expression '[0-9]+' for attribute 'promptTokenCount'").

Root Cause

The catch block in AddEditAiServiceProvider.jsx used e.message (the JavaScript Error object's message) instead of extracting the description field from the API error response body. With the backend now returning a structured { code, message, description } error, the description contains the actionable detail.

What Was Changed

  • AddEditAiServiceProvider.jsx: Updated the catch block to extract response.body.description (falling back to the existing generic message if not present) so the UI shows the precise validation error returned by the backend.

Verification

  • Code review confirmed the change extracts the description field from the backend 400 response body.
  • Backend validation (returning error code 903104 with a specific description) was verified end-to-end via the REST API.

Related backend fix: wso2/carbon-apimgt#13833

…028)

Extract response.body.description from the backend error so the admin UI
displays the precise validation message (e.g. invalid JSONPath expression)
instead of a generic catch-all error text.

Fixes wso2/api-manager#5028
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The Add/Edit AI Service Provider form's save error handler now prefers response.body.description, falls back to the error's message, and otherwise shows a localized generic save error string.

Changes

AI Service Provider Error Messaging

Layer / File(s) Summary
Save Operation Error Handling & locales
portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx, portals/admin/src/main/webapp/site/public/locales/en.json, portals/admin/src/main/webapp/site/public/locales/fr.json
The formSaveCallback catch block now destructures errors into { response, message } and displays response?.body?.description when present, otherwise message, or the new localized key AiServiceProviders.AddEditAiServiceProvider.save.error.generic. The English and French locale files add that key.
sequenceDiagram
  participant AddEditAiServiceProvider
  participant Backend
  participant Alert
  AddEditAiServiceProvider->>Backend: save request
  Backend-->>AddEditAiServiceProvider: error (response.body.description / message)
  AddEditAiServiceProvider->>Alert: display response.body.description or message or localized generic error
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: showing specific backend error descriptions when saving AI service providers, directly addressing issue #5028.
Description check ✅ Passed The description clearly relates to the changeset, explaining the issue, root cause, and specific changes made to extract and display backend error descriptions.
Linked Issues check ✅ Passed The PR successfully addresses the linked issue #5028 by surfacing precise backend validation error descriptions in the admin UI, enabling administrators to identify and correct invalid AI metadata configurations before causing gateway failures.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #5028: updating error handling in AddEditAiServiceProvider.jsx and adding corresponding i18n strings for error messages.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

ashera96
ashera96 previously approved these changes May 11, 2026
@ashera96
Copy link
Copy Markdown
Contributor

@coderabbitai please review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

@ashera96 Sure! I'll start reviewing the PR right away.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx`:
- Around line 432-435: In the AddEditAiServiceProvider component, the error
branch uses Alert.error(response.body.description) even when response.body
exists but has no description; update the condition in the error handling so it
checks for a real description (e.g., response && response.body &&
response.body.description) or simply use optional chaining/fallback like
Alert.error(response?.body?.description || message) so the generic message
fallback is used when description is absent; ensure Alert.error is never called
with undefined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1b5523b0-1f38-47f9-9f4d-a3ee410f479c

📥 Commits

Reviewing files that changed from the base of the PR and between bcc9a00 and 1f0b7cf.

📒 Files selected for processing (1)
  • portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx

…s absent

Use optional chaining so the generic message fallback is reached when
response.body exists but description is missing, preventing Alert.error(undefined).

Addresses CodeRabbit comment: https://github.com/wso2/apim-apps/pull/1347/changes#r3217291794

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ashera96
Copy link
Copy Markdown
Contributor

@coderabbitai please review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch the PR diff
gh pr view 1347 --repo wso2/apim-apps --json files,additions,deletions,title,body

# Get the diff
gh pr diff 1347 --repo wso2/apim-apps

Length of output: 2843


🏁 Script executed:

#!/bin/bash
# Check how other catch blocks in the AiServiceProviders component handle error responses
cat "portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx"

# Check patterns across other components for response.body usage in catch blocks
rg -n "response\.body\.description\|response\.body\.message\|e\.response\.body" \
    portals/admin/src/main/webapp/source/src/app/components/ \
    --type jsx -A2 -B2 2>/dev/null || \
rg -n "response\.body\.description\|response\.body\.message\|e\.response\.body" \
    portals/admin/src/main/webapp/source/src/app/components/ \
    -A2 -B2

# Look for similar error handling patterns in other admin portal components
rg -n "Alert\.error.*description\|response\?\.body\|\.body\.description" \
    portals/admin/src/main/webapp/source/src/app/components/ \
    -A2 -B2 | head -80

Length of output: 61720



@ashera96 I've reviewed the changes. The fix is clean, focused, and correct. Here's the summary:

Review of AddEditAiServiceProvider.jsx

✅ What's Good

  • Safe optional chaining: response?.body?.description correctly guards against undefined when the error doesn't carry a response object (e.g. network errors, plain JS errors).
  • Correct fallback chain: backendDescriptionmessage → silent (no alert) mirrors the backend's structured error shape { code, message, description } and gracefully degrades.
  • Minimal scope: Only the catch block is changed; success flow, validation, and state management are untouched.

⚠️ Pre-existing Issue (not introduced by this PR)

There is a duplicate setSaving(false) call — one inside the catch block and another outside the try/catch before return true:

        } catch (e) {
            // ...
            setSaving(false);   // ← sets saving false on error
        }

        setSaving(false);       // ← redundant: also called after successful try (but component has navigated away via history.push)

        return true;

On the success path, history.push(...) navigates away before this second call is reached, so it's harmless in practice. On the error path it's a no-op duplicate. Worth cleaning up in a follow-up but it's outside the scope of this fix.

Summary

The change correctly surfaces the backend's description field (e.g. "Invalid JSONPath expression '[0-9]+' for attribute 'promptTokenCount'") in the admin portal error alert instead of the generic JS error message. The fix is consistent with how the API client surfaces response bodies elsewhere in the codebase. LGTM!

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx (1)

441-441: 💤 Low value

Consider removing duplicate setSaving(false) (pre-existing).

Line 438 already calls setSaving(false) in the catch block, and line 429 redirects via history.push on success, making this line effectively unreachable or redundant. While this issue predates the current PR, it could be cleaned up for better code clarity.

♻️ Proposed cleanup
             setSaving(false);
         }
-
-        setSaving(false);

         return true;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx`
at line 441, In AddEditAiServiceProvider.jsx remove the redundant
setSaving(false) call that follows the success path (after history.push) because
setSaving(false) is already called in the catch block and the success branch
redirects via history.push; keep the setSaving(false) inside the catch block and
any pre-existing error handling, and delete the duplicate call that is
unreachable after history.push to clean up the component's save flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx`:
- Around line 435-437: The current error handling in
AddEditAiServiceProvider.jsx checks backendDescription and message but leaves a
silent fail when both are falsy; update the conditional that currently has "else
if (message) { Alert.error(message); }" to add a final else branch that calls
Alert.error with a generic fallback (e.g., "An unexpected error occurred" or
"Unable to save provider, please try again") so users always receive feedback
when backendDescription and message are unavailable.

---

Nitpick comments:
In
`@portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx`:
- Line 441: In AddEditAiServiceProvider.jsx remove the redundant
setSaving(false) call that follows the success path (after history.push) because
setSaving(false) is already called in the catch block and the success branch
redirects via history.push; keep the setSaving(false) inside the catch block and
any pre-existing error handling, and delete the duplicate call that is
unreachable after history.push to clean up the component's save flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 126cdc53-6cc1-45ea-88ec-19f0519cc211

📥 Commits

Reviewing files that changed from the base of the PR and between 1f0b7cf and 7732a20.

📒 Files selected for processing (1)
  • portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx`:
- Around line 437-438: Replace the hardcoded Alert.error string in the
AddEditAiServiceProvider component with a localized message via
intl.formatMessage; locate the Alert.error call and pass the result of
intl.formatMessage(...) (using an appropriate message id like a new key for the
generic save error) so the fallback error message is retrieved from the
translations instead of being hardcoded.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ba00466f-4b2f-495e-a712-35b8f04fd7d9

📥 Commits

Reviewing files that changed from the base of the PR and between 27b6952 and 382e6cf.

📒 Files selected for processing (1)
  • portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx

…error message are unavailable

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 26, 2026
@Tharsanan1
Copy link
Copy Markdown
Contributor Author

@CodeRabbit please review and approve

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

@Tharsanan1 The changes look good — the fix correctly extracts response?.body?.description from backend error responses, provides a proper fallback chain, and is minimal in scope. Approving the PR! 🐇✨

✅ Actions performed

Comments resolved and changes approved.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@portals/admin/src/main/webapp/site/public/locales/fr.json`:
- Line 297: The JSON key
"AiServiceProviders.AddEditAiServiceProvider.save.error.generic" is in English;
update its value to a proper French translation (for example: "Une erreur est
survenue lors de l'enregistrement du fournisseur de service d'IA.") so the
French locale file uses French text for this error message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 10603f88-39c7-4f56-8bd4-035c08a5115f

📥 Commits

Reviewing files that changed from the base of the PR and between 382e6cf and 626d3bd.

📒 Files selected for processing (3)
  • portals/admin/src/main/webapp/site/public/locales/en.json
  • portals/admin/src/main/webapp/site/public/locales/fr.json
  • portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx
✅ Files skipped from review due to trivial changes (1)
  • portals/admin/src/main/webapp/site/public/locales/en.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • portals/admin/src/main/webapp/source/src/app/components/AiServiceProviders/AddEditAiServiceProvider.jsx

Comment thread portals/admin/src/main/webapp/site/public/locales/fr.json
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.

APIM GW hangs / does not end transactions in case of AI metadata parsing error

2 participants