Error Types
All errors thrown by the SDK extend from the base ItzamError
class and are structured based on the API response format.
ItzamError
The base error class that all other error types extend from. Contains common properties shared across all error types.
class ItzamError extends Error {
status: number; // HTTP status code
type: string; // Error type name (e.g., "ItzamAuthenticationError")
timestamp: Date; // When the error occurred
documentation: string; // Link to relevant documentation
}
ItzamAuthenticationError
Thrown when there’s an authentication issue (HTTP 401).
try {
await itzam.getModels();
} catch (error) {
if (error instanceof ItzamAuthenticationError) {
console.log("Authentication failed:", error.message);
console.log("Status code:", error.status); // 401
console.log("Documentation:", error.documentation);
}
}
ItzamValidationError
Thrown when the request is invalid (HTTP 400). Includes additional validation details.
try {
await itzam.generateText({
/* invalid params */
});
} catch (error) {
if (error instanceof ItzamValidationError) {
console.log("Invalid request:", error.message);
console.log("Status code:", error.status); // 400
console.log("Expected:", error.expected);
console.log("Received:", error.received);
console.log("Path:", error.path); // Array showing where the error occurred
console.log("Documentation:", error.documentation);
}
}
ItzamNotFoundError
Thrown when a requested resource is not found (HTTP 404). Includes possible valid values.
try {
await itzam.getRunById("non-existent-id");
} catch (error) {
if (error instanceof ItzamNotFoundError) {
console.log("Resource not found:", error.message);
console.log("Status code:", error.status); // 404
console.log("Possible values:", error.possibleValues); // Array of valid options
console.log("Documentation:", error.documentation);
}
}
ItzamServerError
Thrown when there’s a server-side error (HTTP 500).
try {
await itzam.streamText({
/* params */
});
} catch (error) {
if (error instanceof ItzamServerError) {
console.log("Server error:", error.message);
console.log("Status code:", error.status); // 500
console.log("Documentation:", error.documentation);
}
}