generated from PolymeshAssociation/typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 11
/
PolymeshError.ts
37 lines (32 loc) · 958 Bytes
/
PolymeshError.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
import { ErrorCode } from '~/types';
const defaultMessages: {
[errorCode: string]: string;
} = {
[ErrorCode.TransactionReverted]: 'The transaction execution reverted due to an error',
[ErrorCode.TransactionAborted]:
'The transaction was removed from the transaction pool. This might mean that it was malformed (nonce too large/nonce too small/duplicated or invalid transaction)',
[ErrorCode.TransactionRejectedByUser]: 'The user canceled the transaction signature',
};
/**
* Wraps an error to give more information about its type
*/
export class PolymeshError extends Error {
public code: ErrorCode;
public data?: Record<string, unknown>;
/**
* @hidden
*/
constructor({
message,
code,
data,
}: {
message?: string;
code: ErrorCode;
data?: Record<string, unknown>;
}) {
super(message || defaultMessages[code] || `Unknown error, code: ${code}`);
this.code = code;
this.data = data;
}
}