fix(frontend): avoid misleading error message when agent api is disable (#2697) (#2698)

This commit is contained in:
Nan Gao
2026-05-04 03:38:05 +02:00
committed by GitHub
parent f80ac961ec
commit 222a7773cb
5 changed files with 31 additions and 1 deletions
+17
View File
@@ -15,6 +15,17 @@ export class AgentNameCheckError extends Error {
}
}
export class AgentsApiDisabledError extends Error {
constructor(message: string) {
super(message);
this.name = "AgentsApiDisabledError";
}
}
function isAgentsApiDisabledDetail(detail: string | undefined): boolean {
return typeof detail === "string" && detail.includes("agents_api.enabled");
}
export async function listAgents(): Promise<Agent[]> {
const res = await fetch(`${getBackendBaseURL()}/api/agents`);
if (!res.ok) throw new Error(`Failed to load agents: ${res.statusText}`);
@@ -36,6 +47,9 @@ export async function createAgent(request: CreateAgentRequest): Promise<Agent> {
});
if (!res.ok) {
const err = (await res.json().catch(() => ({}))) as { detail?: string };
if (isAgentsApiDisabledDetail(err.detail)) {
throw new AgentsApiDisabledError(err.detail!);
}
throw new Error(err.detail ?? `Failed to create agent: ${res.statusText}`);
}
return res.json() as Promise<Agent>;
@@ -81,6 +95,9 @@ export async function checkAgentName(
if (!res.ok) {
const err = (await res.json().catch(() => ({}))) as { detail?: string };
if (isAgentsApiDisabledDetail(err.detail)) {
throw new AgentsApiDisabledError(err.detail!);
}
if (BACKEND_UNAVAILABLE_STATUSES.has(res.status)) {
throw new AgentNameCheckError(
"Could not reach the DeerFlow backend.",