MCPcopy Index your code
hub / github.com/simstudioai/sim / error_handling_example

Function error_handling_example

packages/python-sdk/examples/basic_usage.py:184–216  ·  view source on GitHub ↗

Example 7: Comprehensive error handling

()

Source from the content-addressed store, hash-verified

182
183
184def 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
219if __name__ == "__main__":

Callers 1

basic_usage.pyFile · 0.85

Calls 2

execute_workflowMethod · 0.95
SimStudioClientClass · 0.90

Tested by

no test coverage detected