-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.js
105 lines (105 loc) · 11.5 KB
/
errors.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
export class WebExtensionUserDenied extends Error {
constructor() {
super('User Denied');
this.toString = () => {
return `[${this.name}]`;
};
this.toJSON = () => {
return {
name: this.name,
};
};
this.name = 'WebExtensionUserDenied';
}
}
export class WebExtensionCreateTxFailed extends Error {
constructor(message) {
super(message);
this.toString = () => {
return `[${this.name} message="${this.message}"]`;
};
this.toJSON = () => {
return {
name: this.name,
message: this.message,
};
};
this.name = 'WebExtensionCreateTxFailed';
}
}
export class WebExtensionTxFailed extends Error {
constructor(txhash, message, raw_message) {
super(message);
this.txhash = txhash;
this.raw_message = raw_message;
this.toString = () => {
return `[${this.name} txhash="${this.txhash}" message="${this.message}"]\n${JSON.stringify(this.raw_message, null, 2)}`;
};
this.toJSON = () => {
return {
name: this.name,
txhash: this.txhash,
message: this.message,
raw_message: this.raw_message,
};
};
this.name = 'WebExtensionTxFailed';
}
}
export class WebExtensionTxUnspecifiedError extends Error {
constructor(message) {
super(message);
this.toString = () => {
return `[${this.name} message="${this.message}"]`;
};
this.toJSON = () => {
return {
name: this.name,
message: this.message,
};
};
this.name = 'WebExtensionTxUnspecifiedError';
}
}
export class WebExtensionLedgerError extends Error {
constructor(code, message) {
super(message);
this.code = code;
this.toString = () => {
return `[${this.name} code="${this.code}" message="${this.message}"]`;
};
this.toJSON = () => {
return {
name: this.name,
code: this.code,
message: this.message,
};
};
this.name = 'WebExtensionLedgerError';
}
}
// ---------------------------------------------
// functions
// ---------------------------------------------
export function isWebExtensionError(error) {
return (error instanceof WebExtensionUserDenied ||
error instanceof WebExtensionCreateTxFailed ||
error instanceof WebExtensionTxFailed ||
error instanceof WebExtensionLedgerError ||
error instanceof WebExtensionTxUnspecifiedError);
}
export function createTxErrorFromJson(json) {
switch (json.name) {
case 'WebExtensionUserDenied':
return new WebExtensionUserDenied();
case 'WebExtensionCreateTxFailed':
return new WebExtensionCreateTxFailed(json.message);
case 'WebExtensionLedgerError':
return new WebExtensionLedgerError(json.code, json.message);
case 'WebExtensionTxFailed':
return new WebExtensionTxFailed(json.txhash, json.message, json.raw_message);
default:
return new WebExtensionTxUnspecifiedError('message' in json ? json.message : String(json));
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL0B0ZXJyYS1tb25leS93ZWItZXh0ZW5zaW9uLWludGVyZmFjZS9lcnJvcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxPQUFPLHNCQUF1QixTQUFRLEtBQUs7SUFDL0M7UUFDRSxLQUFLLENBQUMsYUFBYSxDQUFDLENBQUM7UUFJdkIsYUFBUSxHQUFHLEdBQUcsRUFBRTtZQUNkLE9BQU8sSUFBSSxJQUFJLENBQUMsSUFBSSxHQUFHLENBQUM7UUFDMUIsQ0FBQyxDQUFDO1FBRUYsV0FBTSxHQUFHLEdBQUcsRUFBRTtZQUNaLE9BQU87Z0JBQ0wsSUFBSSxFQUFFLElBQUksQ0FBQyxJQUFJO2FBQ2hCLENBQUM7UUFDSixDQUFDLENBQUM7UUFYQSxJQUFJLENBQUMsSUFBSSxHQUFHLHdCQUF3QixDQUFDO0lBQ3ZDLENBQUM7Q0FXRjtBQUVELE1BQU0sT0FBTywwQkFBMkIsU0FBUSxLQUFLO0lBQ25ELFlBQVksT0FBZTtRQUN6QixLQUFLLENBQUMsT0FBTyxDQUFDLENBQUM7U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