Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions packages/ai/src/auth/oauth/aimlapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ async function request(
options.signal.removeEventListener("abort", onAbort);
}

const label = `${method} ${url}`;

if (options.expectJson === false) {
if (!response.ok) throw new Error(`AI/ML API request failed (HTTP ${response.status})`);
if (!response.ok) throw new Error(`AI/ML API request failed: ${label} -> HTTP ${response.status}`);
return undefined;
}

Expand All @@ -73,12 +75,12 @@ async function request(
const parsed = (await response.json()) as unknown;
if (isRecord(parsed)) body = parsed;
} catch {
if (response.ok) throw new Error("AI/ML API returned invalid JSON");
if (response.ok) throw new Error(`AI/ML API returned invalid JSON: ${label}`);
}

if (!response.ok) {
const detail = errorDetail(body);
throw new Error(`AI/ML API request failed (HTTP ${response.status})${detail ? `: ${detail}` : ""}`);
throw new Error(`AI/ML API request failed: ${label} -> HTTP ${response.status}${detail ? `: ${detail}` : ""}`);
}
return body;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ai/test/aimlapi-oauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe.sequential("AI/ML API OAuth", () => {
prompt: async () => prompts.shift() ?? "",
notify: () => {},
}),
).rejects.toThrow("AI/ML API request failed (HTTP 400): invalid code");
).rejects.toThrow(`AI/ML API request failed: POST ${VERIFY_CODE_URL} -> HTTP 400: invalid code`);
});

it("rejects a successful key response that carries no key", async () => {
Expand Down
Loading