Skip to main content

Error Handling

The SDK throws AgentHiFiveError when the API returns a non-2xx status code. This class extends the standard Error with additional properties for structured error handling.

AgentHiFiveError

import { AgentHiFiveError } from "@agenthifive/sdk";

Properties

PropertyTypeDescription
messagestringHuman-readable error message from the API.
statusCodenumberHTTP status code (e.g., 400, 401, 403, 404, 429, 500).
auditIdstring | undefinedAudit trail ID for the failed request, when available. Useful for support inquiries.
retryAfternumber | undefinedSeconds until retry is allowed. Present on 429 Too Many Requests responses.

Basic Usage

try {
await client.execute({
model: "B",
connectionId: "id",
method: "GET",
url: "https://api.example.com/resource",
});
} catch (err) {
if (err instanceof AgentHiFiveError) {
console.error(`Error ${err.statusCode}: ${err.message}`);
if (err.auditId) console.error("Audit ID:", err.auditId);
}
}

Common Error Codes

StatusMeaningTypical Cause
400Bad RequestInvalid request parameters or missing required fields.
401UnauthorizedMissing or invalid API key.
403ForbiddenInsufficient permissions or policy violation.
404Not FoundConnection, agent, or policy does not exist.
429Too Many RequestsRate limit exceeded. Check retryAfter.
500Internal Server ErrorUnexpected server-side failure.

Retry Pattern for Rate Limits

When the API returns 429, the retryAfter property indicates how many seconds to wait before retrying.

async function executeWithRetry(client: AgentHiFiveClient, options: any, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
return await client.execute(options);
} catch (err) {
if (err instanceof AgentHiFiveError && err.statusCode === 429 && err.retryAfter) {
await new Promise((resolve) => setTimeout(resolve, err.retryAfter! * 1000));
continue;
}
throw err;
}
}
throw new Error("Max retries exceeded");
}
Audit IDs

When reporting issues, always include the auditId from the error. This allows the AgentHiFive team to trace the exact request in the audit log.