forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror-messages.ts
More file actions
211 lines (206 loc) · 7.11 KB
/
Copy patherror-messages.ts
File metadata and controls
211 lines (206 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
* Error message configuration - Single source of truth for all error messages
*
* This centralized configuration system provides:
*
* 🎯 **Benefits:**
* - Single source of truth for all error messages
* - Easy content management without touching code
* - Consistent error messaging across the application
* - Ready for internationalization (i18n)
* - Type-safe configuration with TypeScript
* - Categorized errors for better handling
*
* 📝 **How to use:**
* 1. Add new error patterns to `errorPatterns` object
* 2. Use {context} placeholder for dynamic context injection
* 3. Specify category, severity, and actionable flags
* 4. Add fallback messages for error categories
*
* 🔧 **How to maintain:**
* - Content teams can update messages here without touching logic
* - Developers add new error patterns as needed
* - Use categories to group similar errors
* - Mark errors as actionable if users can fix them
*
* 🌍 **Future i18n support:**
* - Replace `message` string with `messages: { en: "...", es: "..." }`
* - Add locale parameter to helper functions
*
* @example
* ```typescript
* // Adding a new error pattern:
* "CUSTOM_ERROR": {
* message: "Custom error occurred in {context}. Please try again.",
* category: "unknown",
* severity: "error",
* actionable: true
* }
* ```
*/
export interface ErrorPatternConfig {
message: string;
category:
| "network"
| "connection"
| "authentication"
| "validation"
| "unknown";
severity: "error" | "warning" | "info";
actionable: boolean;
}
export interface ErrorConfig {
errorPatterns: Record<string, ErrorPatternConfig>;
fallbacks: Record<string, string>;
contextTemplates: Record<string, string>;
}
export const errorConfig: ErrorConfig = {
errorPatterns: {
ECONNREFUSED: {
message:
"Connection refused - the agent service is not running or not accessible at the specified address. Please check that your agent is started and listening on the correct port.",
category: "network",
severity: "error",
actionable: true,
},
ENOTFOUND: {
message:
"Host not found - the agent service URL appears to be incorrect or the service is not accessible. Please verify the agent endpoint URL.",
category: "network",
severity: "error",
actionable: true,
},
ETIMEDOUT: {
message:
"Connection timeout - the agent service is taking too long to respond. This could indicate network issues or an overloaded agent service.",
category: "network",
severity: "warning",
actionable: true,
},
terminated: {
message:
"Agent {context} was unexpectedly terminated. This often indicates an error in the agent service (e.g., authentication failures, missing environment variables, or agent crashes). Check the agent logs for the root cause.",
category: "connection",
severity: "error",
actionable: true,
},
UND_ERR_SOCKET: {
message:
"Socket connection was closed unexpectedly. This typically indicates the agent service encountered an error and shut down the connection. Check the agent logs for the underlying cause.",
category: "connection",
severity: "error",
actionable: true,
},
other_side_closed: {
message:
"The agent service closed the connection unexpectedly. This usually indicates an error in the agent service. Check the agent logs for more details.",
category: "connection",
severity: "error",
actionable: true,
},
fetch_failed: {
message:
"Failed to connect to the agent service. Please verify the agent is running and the endpoint URL is correct.",
category: "network",
severity: "error",
actionable: true,
},
// Authentication patterns
"401": {
message:
"Authentication failed. Please check your API keys and ensure they are correctly configured.",
category: "authentication",
severity: "error",
actionable: true,
},
"api key": {
message:
"API key error detected. Please verify your API key is correct and has the necessary permissions.",
category: "authentication",
severity: "error",
actionable: true,
},
unauthorized: {
message:
"Unauthorized access. Please check your authentication credentials.",
category: "authentication",
severity: "error",
actionable: true,
},
// Python-specific error patterns
AuthenticationError: {
message:
"OpenAI authentication failed. Please check your OPENAI_API_KEY environment variable or API key configuration.",
category: "authentication",
severity: "error",
actionable: true,
},
"Incorrect API key provided": {
message:
"OpenAI API key is invalid. Please verify your OPENAI_API_KEY is correct and active.",
category: "authentication",
severity: "error",
actionable: true,
},
RateLimitError: {
message:
"OpenAI rate limit exceeded. Please wait a moment and try again, or check your OpenAI usage limits.",
category: "network",
severity: "warning",
actionable: true,
},
InvalidRequestError: {
message:
"Invalid request to OpenAI API. Please check your request parameters and model configuration.",
category: "validation",
severity: "error",
actionable: true,
},
PermissionDeniedError: {
message:
"Permission denied for OpenAI API. Please check your API key permissions and billing status.",
category: "authentication",
severity: "error",
actionable: true,
},
NotFoundError: {
message:
"OpenAI resource not found. Please check your model name and availability.",
category: "validation",
severity: "error",
actionable: true,
},
},
fallbacks: {
network:
"A network error occurred while connecting to the agent service. Please check your connection and ensure the agent service is running.",
connection:
"The connection to the agent service was lost unexpectedly. This may indicate an issue with the agent service.",
authentication:
"Authentication failed. Please check your API keys and credentials.",
validation:
"Invalid input or configuration. Please check your parameters and try again.",
unknown:
"An unexpected error occurred. Please check the logs for more details.",
default:
"An unexpected error occurred. Please check the logs for more details.",
},
contextTemplates: {
connection: "connection",
event_streaming_connection: "event streaming connection",
agent_streaming_connection: "agent streaming connection",
langgraph_agent_connection: "LangGraph agent connection",
},
};
/**
* Helper function to get error pattern configuration by key
*/
export function getErrorPattern(key: string): ErrorPatternConfig | undefined {
return errorConfig.errorPatterns[key];
}
/**
* Helper function to get fallback message by category
*/
export function getFallbackMessage(category: string): string {
return errorConfig.fallbacks[category] || errorConfig.fallbacks.default;
}