-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.js
More file actions
81 lines (72 loc) · 2.45 KB
/
errors.js
File metadata and controls
81 lines (72 loc) · 2.45 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
export class AskhalError extends Error {
constructor(message) {
super(message);
this.name = 'AskhalError';
}
format() {
return this.message;
}
}
export class ConfigError extends AskhalError {
constructor(message, remediation) {
super(message);
this.name = 'ConfigError';
this.remediation = remediation;
}
format() {
return `${this.message}. ${this.remediation}`;
}
}
export class InputError extends AskhalError {
constructor(paramName, value, validRange) {
super(`Invalid ${paramName}: ${value}. Must be ${validRange}.`);
this.name = 'InputError';
this.paramName = paramName;
this.value = value;
this.validRange = validRange;
}
format() {
return this.message;
}
}
export class ContextError extends AskhalError {
constructor(sourcePath, contextType, reason) {
super(`Failed to read ${contextType} context from ${sourcePath}: ${reason}`);
this.name = 'ContextError';
this.sourcePath = sourcePath;
this.contextType = contextType;
this.reason = reason;
}
format() {
return this.message;
}
}
export class ProviderError extends AskhalError {
constructor(providerName, modelName, httpStatus, responseData, message = '') {
super(`Provider error (${httpStatus}) from ${providerName} for model ${modelName}: ${JSON.stringify(responseData)}`);
this.name = 'ProviderError';
this.providerName = providerName;
this.modelName = modelName;
this.httpStatus = httpStatus;
this.responseData = responseData;
this.originalMessage = message;
}
format() {
if (this.httpStatus === 429) {
return `Rate limited (${this.httpStatus}) by ${this.providerName} for model ${this.modelName}. Wait and retry.`;
}
if (this.httpStatus === 401) {
return `Authentication failed (${this.httpStatus}) with ${this.providerName}. Check your AI_PROVIDER_KEY.`;
}
if (this.httpStatus === 403) {
return `Access Forbidden (${this.httpStatus}) with ${this.providerName}. You do not have permission to access the resource.`;
}
if (this.httpStatus === 404) {
return `Model '${this.modelName}' not found on ${this.providerName}. Verify the model identifier.`;
}
if (this.httpStatus >= 500 && this.httpStatus < 600) {
return `${this.providerName} returned a server error (${this.httpStatus}). Try again later.`;
}
return `${this.providerName} error (${this.httpStatus}) for model ${this.modelName}: ${this.originalMessage}`;
}
}