@osimatic/helpers-js 1.0.27 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.txt CHANGED
@@ -34,4 +34,7 @@ majSelectPeriode() / majSelectCompare() -> updatePeriodSelect(form)
34
34
  let URL_REFRESH = ... -> HTTPRequest.setRefreshTokenUrl(URL_REFRESH)
35
35
  let _httpHeaders = {...} -> HTTPRequest.setHeader(key, value);
36
36
  let httpHeaders = {...} -> HTTPRequest.setHeader(key, value);
37
- remplacer l'utilisation des variables httpHeaders / _httpHeaders par HTTPRequest.getHeaders()
37
+ remplacer l'utilisation des variables httpHeaders / _httpHeaders par HTTPRequest.getHeaders()
38
+
39
+ FlashMessage.displayRequestFailure(status, exception, modal) -> FlashMessage.displayError(labelErrorOccured, modal)
40
+ FormHelper.logRequestFailure(status, exception) -> HTTPRequest.logJqueryRequestFailure(jqxhr, status, exception) (le log de l'erreur est devenu inutile car fait de base dans la classe HTTPRequest)
package/flash_message.js CHANGED
@@ -1,9 +1,4 @@
1
1
  class FlashMessage {
2
- static displayRequestFailure(status, exception, modal) {
3
- console.log('request failure. Status: ', status, ' Exception: ', exception);
4
- this.display('danger', typeof labelErrorOccured != 'undefined' ? labelErrorOccured : "Une erreur s'est produite.", false, modal);
5
- }
6
-
7
2
  static displaySuccess(message, reload, modal) {
8
3
  this.display('success', message, reload, modal);
9
4
  }
@@ -32,6 +27,13 @@ class FlashMessage {
32
27
  document.location.reload();
33
28
  }
34
29
  }
30
+
31
+ /** @deprecated **/
32
+ static displayRequestFailure(status, exception, modal) {
33
+ console.log('request failure. Status: ', status, ' Exception: ', exception);
34
+ this.display('danger', typeof labelErrorOccured != 'undefined' ? labelErrorOccured : "Une erreur s'est produite.", false, modal);
35
+ }
36
+
35
37
  }
36
38
 
37
39
  module.exports = { FlashMessage };
package/form_helper.js CHANGED
@@ -1,8 +1,4 @@
1
1
  class FormHelper {
2
- static logRequestFailure(status, exception) {
3
- console.log('request failure. Status: '+status+' ; Exception: '+exception);
4
- }
5
-
6
2
  static resetSelectOption(form, selectName) {
7
3
  form.find('select[name="'+selectName+'"] option').prop('disabled', false).prop('selected', false);
8
4
  }
@@ -257,6 +253,14 @@ class FormHelper {
257
253
 
258
254
  errorsParentDiv.prepend(errorDiv);
259
255
  }
256
+
257
+
258
+
259
+ /** @deprecated **/
260
+ static logRequestFailure(status, exception) {
261
+ console.log('request failure. Status: '+status+' ; Exception: '+exception);
262
+ }
263
+
260
264
  }
261
265
 
262
266
  module.exports = { FormHelper };
package/network.js CHANGED
@@ -43,6 +43,14 @@ class HTTPRequest {
43
43
  return data;
44
44
  }
45
45
 
46
+ static logRequestFailure(response, json) {
47
+ console.error('Request failure. Status: '+response.statusText+' ; HTTP Code : '+response.status, json);
48
+ }
49
+
50
+ static logJqueryRequestFailure(jqxhr, status, errorThrown) {
51
+ console.error('Request failure. Status: '+status+' ; HTTP Code: '+jqxhr.responseJSON.code+(null!=errorThrown && ''!==errorThrown ? ' ; Error message: '+errorThrown : ''), jqxhr.responseJSON);
52
+ }
53
+
46
54
  static async get(url, data, successCallback, errorCallback) {
47
55
  data = this.formatQueryString(data);
48
56
 
@@ -72,12 +80,14 @@ class HTTPRequest {
72
80
  }
73
81
  }
74
82
  catch (e) {
75
- console.log(e);
83
+ console.error(e);
76
84
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
77
85
  errorCallback(response, response.status, e);
78
86
  }
79
87
  return;
80
88
  }
89
+
90
+ HTTPRequest.logRequestFailure(response, jsonData);
81
91
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
82
92
  errorCallback(response, response.status, null, jsonData);
83
93
  }
@@ -93,13 +103,15 @@ class HTTPRequest {
93
103
  dataType: 'json',
94
104
  cache: false,
95
105
  success: (data) => successCallback(data),
96
- error: (jqxhr, status, exception) => {
106
+ error: (jqxhr, status, errorThrown) => {
97
107
  if (typeof jqxhr.responseJSON != 'undefined' && jqxhr.responseJSON.code == 401 && (jqxhr.responseJSON.message === "Expired JWT Token" || (typeof jqxhr.responseJSON['error'] != 'undefined' && jqxhr.responseJSON['error'] === 'expired_token' ))) {
98
108
  HTTPRequest.refreshToken(() => HTTPRequest.get(url, data, successCallback, errorCallback));
99
109
  return;
100
110
  }
111
+
112
+ HTTPRequest.logJqueryRequestFailure(jqxhr, status, errorThrown);
101
113
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
102
- errorCallback(jqxhr, status, exception);
114
+ errorCallback(jqxhr, status, errorThrown);
103
115
  }
104
116
  }
105
117
  });
@@ -130,12 +142,15 @@ class HTTPRequest {
130
142
  if (response.ok) {
131
143
  File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition'));
132
144
  }
133
- else if (typeof errorCallback != 'undefined' && errorCallback != null) {
134
- errorCallback(response, response.status, null);
145
+ else {
146
+ HTTPRequest.logRequestFailure(response, null);
147
+ if (typeof errorCallback != 'undefined' && errorCallback != null) {
148
+ errorCallback(response, response.status, null);
149
+ }
135
150
  }
136
151
  }
137
152
  catch (e) {
138
- console.log(e);
153
+ console.error(e);
139
154
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
140
155
  errorCallback(response, response.status, e);
141
156
  }
@@ -157,13 +172,15 @@ class HTTPRequest {
157
172
  responseType: 'blob'
158
173
  },
159
174
  success: (data, status, jqxhr) => File.download(data, jqxhr.getResponseHeader('Content-Type'), jqxhr.getResponseHeader('Content-Disposition')),
160
- error: (jqxhr, status, exception) => {
175
+ error: (jqxhr, status, errorThrown) => {
161
176
  if (typeof jqxhr.responseJSON != 'undefined' && jqxhr.responseJSON.code == 401 && (jqxhr.responseJSON.message === "Expired JWT Token" || (typeof jqxhr.responseJSON['error'] != 'undefined' && jqxhr.responseJSON['error'] === 'expired_token' ))) {
162
177
  HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback));
163
178
  return;
164
179
  }
180
+
181
+ HTTPRequest.logJqueryRequestFailure(jqxhr, status, errorThrown);
165
182
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
166
- errorCallback(jqxhr, status, exception);
183
+ errorCallback(jqxhr, status, errorThrown);
167
184
  }
168
185
  },
169
186
  complete: (jqxhr, status) => {
@@ -203,7 +220,9 @@ class HTTPRequest {
203
220
  }
204
221
 
205
222
  if (response.ok) {
206
- successCallback(jsonData);
223
+ if (typeof successCallback != 'undefined' && successCallback != null) {
224
+ successCallback(jsonData);
225
+ }
207
226
  return;
208
227
  }
209
228
 
@@ -213,13 +232,14 @@ class HTTPRequest {
213
232
  }
214
233
  }
215
234
  catch (e) {
216
- console.log(e);
235
+ console.error(e);
217
236
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
218
237
  errorCallback(response, response.status, e);
219
238
  }
220
239
  return;
221
240
  }
222
241
 
242
+ HTTPRequest.logRequestFailure(response, jsonData);
223
243
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
224
244
  errorCallback(response, response.status, null, jsonData);
225
245
  }
@@ -237,18 +257,24 @@ class HTTPRequest {
237
257
  cache: false,
238
258
  contentType: false,
239
259
  processData: false,
240
- success: (data) => successCallback(data),
241
- error: (jqxhr, status, exception) => {
260
+ success: (data) => {
261
+ if (typeof successCallback != 'undefined' && successCallback != null) {
262
+ successCallback(data);
263
+ }
264
+ },
265
+ error: (jqxhr, status, errorThrown) => {
242
266
  if (typeof jqxhr.responseJSON != 'undefined' && jqxhr.responseJSON.code == 401 && (jqxhr.responseJSON.message === "Expired JWT Token" || (typeof jqxhr.responseJSON['error'] != 'undefined' && jqxhr.responseJSON['error'] === 'expired_token' ))) {
243
267
  HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback));
244
268
  return;
245
269
  }
246
270
  if (jqxhr.status == 400 && typeof formErrorCallback != 'undefined' && formErrorCallback != null) {
247
- formErrorCallback(jqxhr, status, exception);
271
+ formErrorCallback(jqxhr, status, errorThrown);
248
272
  return;
249
273
  }
274
+
275
+ HTTPRequest.logJqueryRequestFailure(jqxhr, status, errorThrown);
250
276
  if (typeof errorCallback != 'undefined' && errorCallback != null) {
251
- errorCallback(jqxhr, status, exception);
277
+ errorCallback(jqxhr, status, errorThrown);
252
278
  }
253
279
  }
254
280
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"