Skip to content

Commit 418965f

Browse files
committed
fix(sdk): preserve TriggerApiError shape on AgentChat append errors
When AgentChat.appendInputChunk fails non-2xx after the inline-POST refactor, it was throwing a plain Error. Callers of sendRaw, sendMessage, sendHandover, and sendHandoverSkip inspecting error.name === "TriggerApiError" or error.status saw "Error" / undefined instead of the values the prior ApiClient/zodfetch path produced. Synthesize the same shape here so the public error contract is preserved. Matches the equivalent fix already applied to TriggerChatTransport.
1 parent e8d005a commit 418965f

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

packages/trigger-sdk/src/v3/chat-client.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,16 @@ export class AgentChat<TAgent = unknown> {
613613
const response = await this.doFetch(ctx, url, { method: "POST", headers, body });
614614
if (!response.ok) {
615615
const text = await response.text().catch(() => "");
616-
throw new Error(`appendToSessionStream failed: ${response.status} ${text}`);
616+
// Match the error shape that ApiClient/zodfetch produced before the
617+
// inline-POST refactor so callers inspecting `error.name ===
618+
// "TriggerApiError"` or `error.status` keep working.
619+
const err = new Error(`appendToSessionStream failed: ${response.status} ${text}`) as Error & {
620+
name: string;
621+
status: number;
622+
};
623+
err.name = "TriggerApiError";
624+
err.status = response.status;
625+
throw err;
617626
}
618627
}
619628

0 commit comments

Comments
 (0)