|
| 1 | +```markdown |
1 | 2 | # Error Flow Diagram |
2 | 3 |
|
3 | 4 | ## Complete Error Handling Flow |
|
6 | 7 | ┌─────────────────────────────────────────────────────────────────────┐ |
7 | 8 | │ USER SENDS MESSAGE │ |
8 | 9 | └─────────────────────────────────────────────────────────────────────┘ |
9 | | - │ |
10 | | - ▼ |
| 10 | + │ |
| 11 | + ▼ |
11 | 12 | ┌─────────────────────────────────────────────────────────────────────┐ |
12 | 13 | │ WebSocket Handler (main.py) │ |
13 | 14 | │ handle_chat() async function │ |
14 | 15 | └─────────────────────────────────────────────────────────────────────┘ |
15 | | - │ |
16 | | - ▼ |
| 16 | + │ |
| 17 | + ▼ |
17 | 18 | ┌─────────────────────────────────────────────────────────────────────┐ |
18 | 19 | │ ChatService.handle_chat_message() │ |
19 | 20 | │ (service.py) │ |
20 | 21 | └─────────────────────────────────────────────────────────────────────┘ |
21 | | - │ |
22 | | - ▼ |
| 22 | + │ |
| 23 | + ▼ |
23 | 24 | ┌─────────────────────────────────────────────────────────────────────┐ |
24 | 25 | │ ChatOrchestrator.execute() │ |
25 | 26 | │ (orchestrator.py) │ |
26 | 27 | └─────────────────────────────────────────────────────────────────────┘ |
27 | | - │ |
28 | | - ▼ |
| 28 | + │ |
| 29 | + ▼ |
29 | 30 | ┌─────────────────────────────────────────────────────────────────────┐ |
30 | 31 | │ ToolsModeRunner.run() │ |
31 | 32 | │ (modes/tools.py) │ |
32 | 33 | └─────────────────────────────────────────────────────────────────────┘ |
33 | | - │ |
34 | | - ▼ |
| 34 | + │ |
| 35 | + ▼ |
35 | 36 | ┌─────────────────────────────────────────────────────────────────────┐ |
36 | 37 | │ error_utils.safe_call_llm_with_tools() │ |
37 | 38 | │ (utilities/error_utils.py) │ |
38 | 39 | └─────────────────────────────────────────────────────────────────────┘ |
39 | | - │ |
40 | | - ▼ |
| 40 | + │ |
| 41 | + ▼ |
41 | 42 | ┌─────────────────────────────────────────────────────────────────────┐ |
42 | 43 | │ LLMCaller.call_with_tools() │ |
43 | 44 | │ (modules/llm/litellm_caller.py) │ |
44 | 45 | └─────────────────────────────────────────────────────────────────────┘ |
45 | | - │ |
46 | | - ▼ |
| 46 | + │ |
| 47 | + ▼ |
47 | 48 | ┌─────────────────────────────────────────────────────────────────────┐ |
48 | 49 | │ LiteLLM Library │ |
49 | 50 | │ (calls Cerebras/OpenAI/etc.) │ |
50 | 51 | └─────────────────────────────────────────────────────────────────────┘ |
51 | | - │ |
52 | | - ▼ |
53 | | - ┌─────────────┴─────────────┐ |
54 | | - │ │ |
55 | | - ┌──────▼───────┐ ┌───────▼────────┐ |
56 | | - │ SUCCESS │ │ ERROR │ |
57 | | - │ (200 OK) │ │ (Rate Limit) │ |
58 | | - └──────┬───────┘ └───────┬────────┘ |
59 | | - │ │ |
60 | | - │ ▼ |
61 | | - │ ┌──────────────────────────────┐ |
62 | | - │ │ Exception: RateLimitError │ |
63 | | - │ │ "We're experiencing high │ |
64 | | - │ │ traffic right now!" │ |
65 | | - │ └──────────┬───────────────────┘ |
66 | | - │ │ |
67 | | - │ ▼ |
68 | | - │ ┌──────────────────────────────┐ |
69 | | - │ │ error_utils.classify_llm_ │ |
70 | | - │ │ error(exception) │ |
71 | | - │ │ │ |
72 | | - │ │ Returns: │ |
73 | | - │ │ - error_class: RateLimitError│ |
74 | | - │ │ - user_msg: "The AI service │ |
75 | | - │ │ is experiencing high │ |
76 | | - │ │ traffic..." │ |
77 | | - │ │ - log_msg: Full details │ |
78 | | - │ └──────────┬───────────────────┘ |
79 | | - │ │ |
80 | | - │ ▼ |
81 | | - │ ┌──────────────────────────────┐ |
82 | | - │ │ Raise RateLimitError(user_msg)│ |
83 | | - │ └──────────┬───────────────────┘ |
84 | | - │ │ |
85 | | - │ ▼ |
| 52 | + │ |
| 53 | + ▼ |
| 54 | + ┌─────────────┴─────────────┐ |
| 55 | + │ │ |
| 56 | + ┌──────▼───────┐ ┌───────▼────────┐ |
| 57 | + │ SUCCESS │ │ ERROR │ |
| 58 | + │ (200 OK) │ │ (Rate Limit) │ |
| 59 | + └──────┬───────┘ └───────┬────────┘ |
| 60 | + │ │ |
| 61 | + │ ▼ |
| 62 | + │ ┌──────────────────────────────┐ |
| 63 | + │ │ Exception: RateLimitError │ |
| 64 | + │ │ "We're experiencing high │ |
| 65 | + │ │ traffic right now!" │ |
| 66 | + │ └──────────┬───────────────────┘ |
| 67 | + │ │ |
| 68 | + │ ▼ |
| 69 | + │ ┌──────────────────────────────┐ |
| 70 | + │ │ error_utils.classify_llm_ │ |
| 71 | + │ │ error(exception) │ |
| 72 | + │ │ │ |
| 73 | + │ │ Returns: │ |
| 74 | + │ │ - error_class: RateLimitError│ |
| 75 | + │ │ - user_msg: "The AI service │ |
| 76 | + │ │ is experiencing high │ |
| 77 | + │ │ traffic..." │ |
| 78 | + │ │ - log_msg: Full details │ |
| 79 | + │ └──────────┬───────────────────┘ |
| 80 | + │ │ |
| 81 | + │ ▼ |
| 82 | + │ ┌──────────────────────────────┐ |
| 83 | + │ │ Raise RateLimitError(user_msg)│ |
| 84 | + │ └──────────┬───────────────────┘ |
| 85 | + │ │ |
| 86 | + │ ▼ |
86 | 87 | ┌───────────────────┴─────────────────────────┴─────────────────────┐ |
87 | 88 | │ Back to WebSocket Handler (main.py) │ |
88 | 89 | │ Exception Catching │ |
89 | 90 | └────────────────────────────────────────────────────────────────────┘ |
90 | | - │ |
91 | | - ┌─────────────┴─────────────┐ |
92 | | - │ │ |
93 | | - ┌──────▼────────┐ ┌────────▼────────────┐ |
94 | | - │ except │ │ except │ |
95 | | - │ RateLimitError │ │ LLMTimeoutError │ |
96 | | - │ │ │ LLMAuth...Error │ |
97 | | - │ Send to user: │ │ ValidationError │ |
98 | | - │ { │ │ etc. │ |
99 | | - │ type: "error",│ │ │ |
100 | | - │ message: user │ │ Send appropriate │ |
101 | | - │ friendly msg,│ │ message to user │ |
102 | | - │ error_type: │ │ │ |
103 | | - │ "rate_limit" │ │ │ |
104 | | - │ } │ │ │ |
105 | | - └───────┬────────┘ └────────┬────────────┘ |
106 | | - │ │ |
107 | | - └──────────┬───────────────┘ |
108 | | - │ |
109 | | - ▼ |
| 91 | + │ |
| 92 | + ┌─────────────┴─────────────┐ |
| 93 | + │ │ |
| 94 | + ┌──────▼────────┐ ┌────────▼────────────┐ |
| 95 | + │ except │ │ except │ |
| 96 | + │ RateLimitError │ │ LLMTimeoutError │ |
| 97 | + │ │ │ LLMAuth...Error │ |
| 98 | + │ Send to user: │ │ ValidationError │ |
| 99 | + │ { │ │ etc. │ |
| 100 | + │ type: "error",│ │ │ |
| 101 | + │ message: user │ │ Send appropriate │ |
| 102 | + │ friendly msg,│ │ message to user │ |
| 103 | + │ error_type: │ │ │ |
| 104 | + │ "rate_limit" │ │ │ |
| 105 | + │ } │ │ │ |
| 106 | + └───────┬────────┘ └────────┬────────────┘ |
| 107 | + │ │ |
| 108 | + └──────────┬───────────────┘ |
| 109 | + │ |
| 110 | + ▼ |
110 | 111 | ┌─────────────────────────────────────────────────────────────────────┐ |
111 | 112 | │ WebSocket Message Sent │ |
112 | 113 | │ { │ |
|
115 | 116 | │ "error_type": "rate_limit" │ |
116 | 117 | │ } │ |
117 | 118 | └─────────────────────────────────────────────────────────────────────┘ |
118 | | - │ |
119 | | - ▼ |
| 119 | + │ |
| 120 | + ▼ |
120 | 121 | ┌─────────────────────────────────────────────────────────────────────┐ |
121 | 122 | │ Frontend (websocketHandlers.js) │ |
122 | 123 | │ │ |
|
128 | 129 | │ timestamp: new Date().toISOString() │ |
129 | 130 | │ }) │ |
130 | 131 | └─────────────────────────────────────────────────────────────────────┘ |
131 | | - │ |
132 | | - ▼ |
| 132 | + │ |
| 133 | + ▼ |
133 | 134 | ┌─────────────────────────────────────────────────────────────────────┐ |
134 | 135 | │ UI DISPLAYS ERROR │ |
135 | 136 | │ │ |
|
152 | 153 | 4. **Error Type Field**: The `error_type` field allows the frontend to potentially handle different error types differently in the future (e.g., automatic retry for timeouts). |
153 | 154 |
|
154 | 155 | 5. **No Sensitive Data Exposure**: API keys, stack traces, and other sensitive information are never sent to the frontend. |
| 156 | +``` |
| 157 | + |
0 commit comments