-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patherrors.ts
38 lines (35 loc) · 1.08 KB
/
errors.ts
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
export enum AptosWalletErrorCode {
Unauthorized = 4100,
Unsupported = 4200,
InternalError = -30001
}
export const AptosWalletErrors = Object.freeze({
[AptosWalletErrorCode.Unauthorized]: {
status: 'Unauthorized',
message: 'The requested method and/or account has not been authorized by the user.'
},
[AptosWalletErrorCode.InternalError]: {
status: 'Internal error',
message: 'Something went wrong within the wallet.'
},
[AptosWalletErrorCode.Unsupported]: {
status: 'Unsupported',
message: 'The requested feature is not supported.'
}
})
export class AptosWalletError extends Error {
readonly code: number
readonly status: string
constructor(code: number, message?: string) {
super(
message ??
AptosWalletErrors[code as keyof typeof AptosWalletErrors]?.message ??
'Unknown error occurred'
)
this.code = code
this.status =
AptosWalletErrors[code as keyof typeof AptosWalletErrors]?.status ?? 'Unknown error'
this.name = 'AptosWalletError'
Object.setPrototypeOf(this, AptosWalletError.prototype)
}
}