-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbnm-http-codes.js
206 lines (167 loc) · 4.21 KB
/
bnm-http-codes.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
'use strict';
Polymer.BnmHttpCodesBehavior = {
properties: {
promise: {
type: Object
}
},
observers: [
'_promiseChange(promise)'
],
/**
*
*/
_showFormatError(wc, errorCode, messageError) {
switch (/*app.isLogin && */errorCode) {
/* HTTP 300 */
// etc..
/* HTTP 400 */
case 400:
this.errorCode400(wc, messageError);
break;
case 401:
this.errorCode401(wc, messageError);
break;
case 404:
this.errorCode404(wc, messageError);
break;
case 412:
this.errorCode412(wc);
break;
case 413:
this.errorCode413(wc);
break;
case 402:
case 403:
case 405:
case 408:
this.errorRequestError(wc);
break;
case 406:
this.errorCode406(wc);
break;
case 499:
this.errorRequestUnknown(wc);
break;
/* HTTP 500 */
case 502:
this.errorCode502(wc, messageError);
break;
case 500:
case 501:
case 503:
case 504:
case 505:
this.errorServerError(wc);
break;
default:
break;
}
},
/**
* Observer
*/
_promiseChange(promise) {
//TODO:
// Если Frontend определил, что значение введено некорректно, то такое значение на Backend отправляться не должно.
// if (_this && _this.querySelectorAll('input-format #errorMessage.error').length) {
// return reject();
// }
promise
.then(() => {
})
.catch(error => {
if (typeof error === 'object') {
let messageError;
if (error.message.error) {
messageError = error.message.error.message;
} else {
messageError = error.message.message;
}
this._showFormatError(
this.closest('widget-card'),
error.code,
messageError
);
}
if (typeof error === 'string') {
console.error(error);
}
});
},
/**
* Ошибка 400
*/
errorCode400(wc, error) {
console.warn(error);
const errorMessage = 'Некорректно указано значение поля';
if (wc) {
const inputFormat = wc.querySelectorAll('input-format');
if (inputFormat && inputFormat.length === 1) {
inputFormat[0].errorMessage = errorMessage;
} else {
switch (typeof error) {
case 'string':
NOTIFICATION.showFormError(wc, errorMessage);
break;
default:
NOTIFICATION.showFormError(wc, errorMessage);
break;
}
}
}
},
/**
* Ошибка 401
*/
errorCode401(wc, error) {
console.warn('code 401');
error = error || 'Запрос вернул ошибку 401';
NOTIFICATION.showFormError(wc, error);
app.onLogout();
},
/**
* Ошибка 404
*/
errorCode404(wc, error) {
console.warn('404: not found');
error = error || 'Запрос вернул ошибку 404';
NOTIFICATION.showFormError(wc, error);
},
errorCode406(wc) {
const error = 'Недопустимое действие';
NOTIFICATION.showFormError(wc, error);
},
/**
* Ошибка 502
*/
errorCode502(wc, error) {
console.warn('502: server error');
error = error || 'Сервер недоступен';
NOTIFICATION.showFormError(wc, error);
},
/**
* Неизвестные ошибки 400
*/
errorRequestError(wc) {
NOTIFICATION.showFormError(wc, 'Ошибка обработки запроса');
},
errorRequestUnknown(wc) {
NOTIFICATION.showFormError(wc, 'Запрос прервался');
},
/**
* 412
*/
errorCode412(wc) {
NOTIFICATION.showFormError(wc, 'Ошибка загрузки данных');
},
errorCode413(wc) {
NOTIFICATION.showFormError(wc, 'Превышение допустимого размера файла');
},
/**
* Неизвестные ошибки 500
*/
errorServerError(wc) {
NOTIFICATION.showFormError(wc, 'Сервер недоступен');
}
};