Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/app/[owner]/[repo]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,15 @@ IMPORTANT:
// Extract wiki structure from response
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]+/);
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.

medium

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.

Suggested change
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]+/);
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.

medium

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.

Suggested change
const generalErrorMatch = responseText.match(/\nError:\s*[^\n]+/);
const generalErrorMatch = responseText.match(/(?:^|\n)Error:\s*[^\n]+/);

if (generalErrorMatch) {
throw new Error(generalErrorMatch[0].trim());
}
throw new Error('No valid XML found in response');
}

Expand Down
Loading