mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
[Skills UI] fix non-JSON error handling in testGitHubSkillConnection and createSkillFromGitHub
This commit is contained in:
parent
5090d5e263
commit
6c8fc0ff6d
1 changed files with 30 additions and 12 deletions
|
|
@ -10014,15 +10014,24 @@ export const testGitHubSkillConnection = async (
|
|||
pat: string,
|
||||
): Promise<{ status: string; message?: string }> => {
|
||||
const base = proxyBaseUrl ?? "";
|
||||
const response = await fetch(`${base}/v1/skills/test-github-connection`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
[globalLitellmHeaderName]: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ repo_url: repoUrl, github_pat: pat }),
|
||||
});
|
||||
return response.json();
|
||||
try {
|
||||
const response = await fetch(`${base}/v1/skills/test-github-connection`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
[globalLitellmHeaderName]: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ repo_url: repoUrl, github_pat: pat }),
|
||||
});
|
||||
const text = await response.text();
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch {
|
||||
return { status: "error", message: text || `HTTP ${response.status}` };
|
||||
}
|
||||
} catch (e: any) {
|
||||
return { status: "error", message: e?.message ?? "Network error" };
|
||||
}
|
||||
};
|
||||
|
||||
export const createSkillFromGitHub = async (
|
||||
|
|
@ -10045,9 +10054,18 @@ export const createSkillFromGitHub = async (
|
|||
display_title: displayTitle || undefined,
|
||||
}),
|
||||
});
|
||||
const text = await response.text();
|
||||
if (!response.ok) {
|
||||
const err = await response.text();
|
||||
throw new Error(err);
|
||||
let message = text;
|
||||
try {
|
||||
const parsed = JSON.parse(text);
|
||||
message = parsed?.detail ?? parsed?.message ?? text;
|
||||
} catch { /* use raw text */ }
|
||||
throw new Error(message || `HTTP ${response.status}`);
|
||||
}
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch {
|
||||
throw new Error(`Unexpected response: ${text}`);
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue