fix: surface actual API errors instead of generic 'No valid XML' message#513
fix: surface actual API errors instead of generic 'No valid XML' message#513octo-patch wants to merge 1 commit intoAsyncFuncAI:mainfrom
Conversation
…age (fixes AsyncFuncAI#493) When wiki generation fails due to upstream API errors (e.g. rate limiting 429), the frontend now extracts and displays the actual error from the response text. Previously, all failures without valid XML were shown as 'No valid XML found in response', which misled users into thinking their repository URL was wrong. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
There was a problem hiding this comment.
Code Review
This pull request improves error handling when parsing the wiki structure by attempting to extract and surface specific API or general error messages from the response text. Feedback was provided to make the error-matching regular expressions more robust by accounting for hyphens in API provider names and ensuring matches work at the start of the response string.
| const xmlMatch = responseText.match(/<wiki_structure>[\s\S]*?<\/wiki_structure>/m); | ||
| if (!xmlMatch) { | ||
| // Surface the actual API error instead of a generic message | ||
| const apiErrorMatch = responseText.match(/Error with [\w][\w ]*API:\s*[^\n]+/); |
There was a problem hiding this comment.
The regex for apiErrorMatch might fail if the provider name contains hyphens (e.g., "Google-Cloud"). Additionally, for consistency with the general error check and to ensure the error is captured even if it's at the very beginning of the response, consider using (?:^|\n) as a prefix.
| const apiErrorMatch = responseText.match(/Error with [\w][\w ]*API:\s*[^\n]+/); | |
| const apiErrorMatch = responseText.match(/(?:^|\n)Error with [\w][\w -]*API:\s*[^\n]+/); |
| if (apiErrorMatch) { | ||
| throw new Error(apiErrorMatch[0].trim()); | ||
| } | ||
| const generalErrorMatch = responseText.match(/\nError:\s*[^\n]+/); |
There was a problem hiding this comment.
The regex for generalErrorMatch currently requires a leading newline (\n). If the API response starts directly with the error message (e.g., "Error: ..."), this check will fail. Using (?:^|\n) allows the match to occur at the beginning of the string or after a newline, making the error detection more robust.
| const generalErrorMatch = responseText.match(/\nError:\s*[^\n]+/); | |
| const generalErrorMatch = responseText.match(/(?:^|\n)Error:\s*[^\n]+/); |
Fixes #493
Problem
When wiki generation fails due to upstream API errors (e.g. rate limiting 429), the frontend only shows a generic message:
The actual error (e.g.
Error code: 429 - RPM limit reached) is only visible in container logs, making debugging very difficult. Users are misled into thinking their repository URL is wrong.Solution
After the existing specific error checks (OPENAI_API_KEY missing, Ollama model not found), before throwing the generic error, the code now attempts to extract and surface the actual API error message from the response text:
Error with <Provider> API: <message>(e.g.Error with Openai API: Error code: 429 - ...)\nError: <message>patterns'No valid XML found in response'if no API error is detectedTesting
Error with Openai API: Error code: 429 - {'error': {'message': 'RPM limit reached'}}instead of the misleading generic message