diff --git a/packages/ai/src/auth/oauth/aimlapi.ts b/packages/ai/src/auth/oauth/aimlapi.ts index a41665514a8..d2611f95bf7 100644 --- a/packages/ai/src/auth/oauth/aimlapi.ts +++ b/packages/ai/src/auth/oauth/aimlapi.ts @@ -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; } @@ -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; } diff --git a/packages/ai/test/aimlapi-oauth.test.ts b/packages/ai/test/aimlapi-oauth.test.ts index 9e26ccc5868..60c2ac38aef 100644 --- a/packages/ai/test/aimlapi-oauth.test.ts +++ b/packages/ai/test/aimlapi-oauth.test.ts @@ -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 () => {