forked from dwmkerr/terminal-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.ts
More file actions
73 lines (68 loc) · 2.11 KB
/
errors.ts
File metadata and controls
73 lines (68 loc) · 2.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
export const enum ErrorCode {
// Fallback when we cannot determine what the error is (e.g. we cannot
// translate an upstream error).
Unknown = 1,
ExitPrompt = 11,
InvalidConfiguration = 12,
Connection = 13,
InvalidOperation = 14,
FileLoadError = 15,
CompatibilityError = 16,
OpenAIError = 20,
OpenAIPermissionDeniedError = 21,
OpenAIAuthenticationError = 22,
OpenAIRateLimitError = 23,
OpenAIBadRequestError = 24,
// Integrations.
LangfuseError = 30,
}
export function errorCodeName(errorCode: ErrorCode): string {
switch (errorCode) {
case ErrorCode.Unknown:
return "Unknown Error";
case ErrorCode.ExitPrompt:
return "Exit Prompt";
case ErrorCode.InvalidConfiguration:
return "Invalid Configuration";
case ErrorCode.Connection:
return "Connection Error";
case ErrorCode.InvalidOperation:
return "Invalid Operation";
case ErrorCode.FileLoadError:
return "File Load Error";
case ErrorCode.CompatibilityError:
return "Compatibility Error";
case ErrorCode.OpenAIError:
return "OpenAI Error";
case ErrorCode.OpenAIPermissionDeniedError:
return "OpenAI Permission Denied";
case ErrorCode.OpenAIAuthenticationError:
return "OpenAI Authentication Error";
case ErrorCode.OpenAIRateLimitError:
return "OpenAI Rate Limit Error";
case ErrorCode.OpenAIBadRequestError:
return "OpenAI Bad Request Error";
// Integrations.
case ErrorCode.LangfuseError:
return "Langfuse Error";
default:
return "Unknown Error";
}
}
// When we call 'translateError' we will always transform into this error type.
export class TerminalAIError extends Error {
errorCode: ErrorCode;
innerError: Error | unknown | undefined;
constructor(
errorCode: ErrorCode,
message: string,
innerError: Error | unknown | undefined = undefined,
) {
super(message);
this.name = errorCodeName(errorCode);
this.errorCode = errorCode;
this.innerError = innerError;
Object.setPrototypeOf(this, TerminalAIError.prototype);
Error.captureStackTrace(this, this.constructor);
}
}