Skip to main content

Errors

The SDK throws ApiError for non-2xx API responses and network failures.
import { ApiError, TryAgent } from "@tryagent/sdk";

const tryagent = new TryAgent({
  apiKey: process.env.TRYAGENT_API_KEY!,
});

try {
  await tryagent.escalate("orders.auth_doc", input);
} catch (error) {
  if (error instanceof ApiError) {
    console.error(error.status, error.requestId, error.body);
    throw error;
  }

  throw error;
}
ApiError.status is 0 for network failures. For API responses, status is the HTTP status code, body contains the parsed response when available, and requestId is populated from the response headers when present.

WebhookSignatureError

webhooks.constructEvent throws WebhookSignatureError when the x-tryagent-signature header fails HMAC verification. Treat it as a 401 — a verified event is safe to act on, an unverified one is not.
import { WebhookSignatureError } from "@tryagent/sdk";

try {
  const event = await tryagent.webhooks.constructEvent({
    payload: body,
    signature: request.headers.get("x-tryagent-signature"),
    secret: process.env.TRYAGENT_WEBHOOK_SECRET!,
  });
} catch (error) {
  if (error instanceof WebhookSignatureError) {
    return Response.json({ error: "Invalid signature" }, { status: 401 });
  }
  throw error;
}