Example 7: Comprehensive error handling
()
| 182 | |
| 183 | |
| 184 | def error_handling_example(): |
| 185 | """Example 7: Comprehensive error handling""" |
| 186 | client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) |
| 187 | |
| 188 | try: |
| 189 | result = client.execute_workflow("your-workflow-id") |
| 190 | |
| 191 | if result.success: |
| 192 | print("✅ Workflow executed successfully!") |
| 193 | print(f"Output: {result.output}") |
| 194 | return result |
| 195 | else: |
| 196 | print(f"❌ Workflow failed: {result.error}") |
| 197 | return result |
| 198 | except SimStudioError as error: |
| 199 | if error.code == "UNAUTHORIZED": |
| 200 | print("❌ Invalid API key") |
| 201 | elif error.code == "TIMEOUT": |
| 202 | print("⏱️ Workflow execution timed out") |
| 203 | elif error.code == "USAGE_LIMIT_EXCEEDED": |
| 204 | print("💳 Usage limit exceeded") |
| 205 | elif error.code == "INVALID_JSON": |
| 206 | print("📝 Invalid JSON in request body") |
| 207 | elif error.status == 404: |
| 208 | print("🔍 Workflow not found") |
| 209 | elif error.status == 403: |
| 210 | print("🚫 Workflow is not deployed") |
| 211 | else: |
| 212 | print(f"⚠️ Workflow error: {error}") |
| 213 | raise |
| 214 | except Exception as error: |
| 215 | print(f"💥 Unexpected error: {error}") |
| 216 | raise |
| 217 | |
| 218 | |
| 219 | if __name__ == "__main__": |
no test coverage detected