-
Notifications
You must be signed in to change notification settings - Fork 13
/
X.js
101 lines (84 loc) · 1.96 KB
/
X.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
const errorCodes = require('./errorCodes');
class Base extends Error {
constructor(args = {}) {
super();
if (!args.code) throw new Error('Code required');
if (!args.message) throw new Error('Message required');
this.code = args.code;
this.message = args.message;
}
}
class MethodNotFound extends Base {
constructor() {
super({
code: errorCodes.METHOD_NOT_FOUND,
message: 'Method not found'
});
}
}
class InvalidParams extends Base {
constructor() {
super({
code: errorCodes.INVALID_PARAMS,
message: 'Invalid params'
});
}
}
class InternalError extends Base {
constructor() {
super({
code: errorCodes.INTERNAL_ERROR,
message: 'Internal error'
});
}
}
class ParseError extends Base {
constructor() {
super({
code: errorCodes.PARSE_ERROR,
message: 'Parse error'
});
}
}
class InvalidRequest extends Base {
constructor() {
super({
code: errorCodes.INVALID_REQUEST,
message: 'Invalid request'
});
}
}
class ServerError extends Base {
}
class RequestTimout extends ServerError {
constructor() {
super({
code: errorCodes.REQUEST_TIMEOUT,
message: 'Request exceeded maximum execution time'
});
}
}
// For backward compatibility of RequestTimout class
class RequestTimeout extends RequestTimout {
}
class ExecutionError extends ServerError {
constructor({data = null} = {}) {
super({
code: errorCodes.EXECUTION_ERROR,
message: 'Method has returned error'
});
this.data = data;
}
}
module.exports = {
Base,
MethodNotFound,
InvalidRequest,
InvalidParams,
InternalError,
ServerError,
ParseError,
RequestTimout, // For backward compatibility
RequestTimeout,
ExecutionError
};