-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.js
149 lines (136 loc) · 3.78 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*global module */
module.exports = (function(){
"use strict";
function PandaError(code, error, message, data) {
if (Error.captureStackTrace)
Error.captureStackTrace(this, this.constructor);
this.name = 'PandaError';
if (isNaN(code)) {
data = error;
error = code;
}
if (typeof error === 'object') {
this.code = error.code;
if(!this.code) this.code = 0;
this.error = error.error;
this.message = error.message;
this.data = error.data;
if(!this.data) this.data = data;
} else {
this.code = code;
this.error = error;
this.message = message;
this.data = data;
}
}
PandaError.prototype = Object.create(Error.prototype);
PandaError.prototype.constructor = PandaError;
function HttpError(code, error, message, data){
this.name = 'HttpError';
this.code = code;
this.error = error;
this.message = message;
this.data = data;
}
HttpError.prototype = Object.create(Error.prototype);
HttpError.prototype.constructor = HttpError;
var ERROR_TYPE = {
0: 'error',
1: 'type error',
2: 'oauth error',
3: 'params error',
4: 'timeout error'
};
var ERROR = {
TYPE: {
code: 1,
error: ERROR_TYPE[1],
message: 'invalid type'
},
OPTIONS: {
code: 1,
error: ERROR_TYPE[1],
message: 'missing or invalid options object'
},
SHOP: {
code: 1,
error: ERROR_TYPE[1],
message: 'shop must be a hostname string'
},
CALLBACK: {
code: 1,
error: ERROR_TYPE[1],
message: 'callback must be a function'
},
LOGGER: {
code: 1,
error: ERROR_TYPE[1],
message: 'logger must be a function'
},
OAUTH: {
code: 1,
error: ERROR_TYPE[1],
message: 'oauth must be an object'
},
STREAM: {
code: 1,
error: ERROR_TYPE[1],
message: 'missing or invalid stream class'
},
PARAMS: {
code: 1,
error: ERROR_TYPE[1],
message: 'missing parameters object'
},
OAUTH_SCOPE: {
code: 2,
error: ERROR_TYPE[2],
message: 'missing or invalid oauth scope'
},
OAUTH_API_KEY: {
code: 2,
error: ERROR_TYPE[2],
message: 'missing or invalid oauth api_key'
},
OAUTH_PRIVATE_KEY: {
code: 2,
error: ERROR_TYPE[2],
message: 'missing or invalid oauth private_key'
},
OAUTH_SIGNATURE: {
code: 2,
error: ERROR_TYPE[2],
message: 'oauth signature mismatch'
},
OAUTH_SHARED_SECRET: {
code: 2,
error: ERROR_TYPE[2],
message: 'missing or invalid oauth shared_secret'
},
SIGNATURE_PARAM: {
code: 3,
error: ERROR_TYPE[3],
message: 'missing or invalid signature'
},
CODE_PARAM: {
code: 3,
error: ERROR_TYPE[3],
message: 'missing or invalid code'
},
TIMEOUT: {
code: 4,
error: ERROR_TYPE[4],
message: 'operation timed out'
},
HTTP_REQUEST: {
code: 5,
error: ERROR_TYPE[5],
message: 'request failed'
}
};
PandaError.ERROR = ERROR;
return {
PandaError: PandaError,
HttpError: HttpError
};
}());