Error Recovery
Use fallbacks to handle failures gracefully.
Error Recovery
# ✓ Good - Graceful degradation
def invoke_with_fallback(client, mcp, action, token, params, fallback_value=None):
try:
result = client.invoke(mcp, action, token, params)
if result["success"]:
return result["data"]
else:
logger.warning(f"MCP failed: {result['error']}")
return fallback_value
except Exception as e:
logger.error(f"Invoke failed: {e}")
return fallback_value
# Usage
data = invoke_with_fallback(
client, "data-mcp", "fetch", token, {},
fallback_value=[] # Empty list if fails
)import { ArmorIQClient, IntentToken, MCPInvocationException } from '@armoriq/sdk';
// ✓ Good - Graceful degradation
async function invokeWithFallback<T>(
client: ArmorIQClient,
mcp: string,
action: string,
token: IntentToken,
params: Record<string, any>,
fallbackValue: T
): Promise<T> {
try {
const result = await client.invoke(mcp, action, token, params);
return result.result as T;
} catch (error) {
if (error instanceof MCPInvocationException) {
console.warn(`MCP failed: ${error.message}`);
} else {
console.error(`Invoke failed: ${error}`);
}
return fallbackValue;
}
}
// Usage
const data = await invokeWithFallback(
client,
'data-mcp',
'fetch',
token,
{},
[] // Empty array if fails
);