forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.ts
More file actions
32 lines (29 loc) · 769 Bytes
/
Copy patherrors.ts
File metadata and controls
32 lines (29 loc) · 769 Bytes
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
export class SdkError extends Error {
public code: string;
constructor(message: string, code: string = 'UNKNOWN_ERROR') {
super(message);
this.name = 'SdkError';
this.code = code;
}
}
export class ContractError extends SdkError {
constructor(message: string) {
super(message, 'CONTRACT_ERROR');
this.name = 'ContractError';
}
}
export class NetworkError extends SdkError {
constructor(message: string) {
super(message, 'NETWORK_ERROR');
this.name = 'NetworkError';
}
}
export function normalizeError(err: unknown): SdkError {
if (err instanceof SdkError) {
return err;
}
if (err instanceof Error) {
return new SdkError(err.message, 'INTERNAL_ERROR');
}
return new SdkError(String(err), 'UNKNOWN_ERROR');
}