Error Handling
Error Handling
Exception Hierarchy
ArmorIQError (base)
├── AuthenticationError
│ ├── InvalidAPIKeyError
│ └── APIKeyExpiredError
├── TokenError
│ ├── TokenExpiredError
│ ├── TokenInvalidError
│ └── TokenIssuanceError
├── VerificationError
│ ├── MerkleProofError
│ └── SignatureError
├── MCPError
│ ├── MCPNotFoundError
│ ├── ActionNotFoundError
│ └── InvalidParametersError
├── NetworkError
│ ├── ConnectionError
│ └── TimeoutError
└── ValidationErrorArmorIQException (base)
├── ConfigurationException
├── InvalidTokenException
│ └── TokenExpiredException
├── IntentMismatchException
├── MCPInvocationException
└── DelegationExceptionCatching Exceptions
from armoriq_sdk.exceptions import (
ArmorIQError,
AuthenticationError,
TokenExpiredError,
VerificationError,
MCPError,
NetworkError
)
try:
captured_plan = client.capture_plan(
llm="gpt-4",
prompt="Analyze the data",
plan=plan_dict # Optional: provide structure
)
token_response = client.get_intent_token(captured_plan)
result = client.invoke("analytics-mcp", "analyze", token_response["token"], params)
except AuthenticationError as e:
# API key invalid or expired
logger.error(f"Authentication failed: {e}")
# Refresh API key
except TokenExpiredError as e:
# Token expired, get new one
logger.warning(f"Token expired: {e}")
token_response = client.get_intent_token(capture_plan)
result = client.invoke("analytics-mcp", "analyze", token_response["token"], params)
except VerificationError as e:
# Action not in plan or verification failed
logger.error(f"Verification failed: {e}")
# Recreate plan with correct actions
except MCPError as e:
# MCP execution failed
logger.error(f"MCP error: {e.message}")
# Handle MCP-specific error
except NetworkError as e:
# Network issues
logger.error(f"Network error: {e}")
# Retry or use fallback
except ArmorIQError as e:
# Catch-all for any ArmorIQ error
logger.error(f"ArmorIQ error: {e}")
except Exception as e:
# Unexpected error
logger.exception(f"Unexpected error: {e}")import {
ArmorIQException,
ConfigurationException,
InvalidTokenException,
TokenExpiredException,
IntentMismatchException,
MCPInvocationException,
DelegationException
} from '@armoriq/sdk';
try {
const capturedPlan = client.capturePlan(
'gpt-4',
'Analyze the data',
planDict // Optional: provide structure
);
const token = await client.getIntentToken(capturedPlan);
const result = await client.invoke('analytics-mcp', 'analyze', token, params);
} catch (error) {
if (error instanceof ConfigurationException) {
// API key invalid or missing
console.error(`Configuration error: ${error.message}`);
// Check API key format
} else if (error instanceof TokenExpiredException) {
// Token expired, get new one
console.warn(`Token expired: ${error.message}`);
const newToken = await client.getIntentToken(capturedPlan);
const result = await client.invoke('analytics-mcp', 'analyze', newToken, params);
} else if (error instanceof IntentMismatchException) {
// Action not in plan or verification failed
console.error(`Intent mismatch: ${error.message}`);
console.error(`Action: ${error.action}, Plan hash: ${error.planHash}`);
// Recreate plan with correct actions
} else if (error instanceof MCPInvocationException) {
// MCP execution failed
console.error(`MCP error: ${error.message}`);
console.error(`MCP: ${error.mcp}, Action: ${error.action}`);
// Handle MCP-specific error
} else if (error instanceof InvalidTokenException) {
// Token invalid
console.error(`Token error: ${error.message}`);
} else if (error instanceof ArmorIQException) {
// Catch-all for any ArmorIQ error
console.error(`ArmorIQ error: ${error.message}`);
} else {
// Unexpected error
console.error(`Unexpected error: ${error}`);
}
}Error Response Format
When invoke() returns success: False:
{
"success": false,
"error": "str",
"error_code": "str",
"details": {},
"mcp": "str",
"action": "str"
}Error Codes
AUTH_INVALID_KEY: Invalid API keyAUTH_EXPIRED_KEY: API key expiredTOKEN_EXPIRED: Token expiredTOKEN_INVALID: Token signature invalidVERIFICATION_FAILED: IAP verification failedMERKLE_PROOF_INVALID: Merkle proof validation failedMCP_NOT_FOUND: MCP server not foundACTION_NOT_FOUND: Action not availableINVALID_PARAMS: Invalid parametersNETWORK_ERROR: Network connection failedTIMEOUT: Request timed outRATE_LIMIT: Rate limit exceeded