@osimatic/helpers-js 1.1.55 → 1.1.57

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/form_helper.js CHANGED
@@ -234,7 +234,7 @@ class FormHelper {
234
234
  // Messages erreur
235
235
  // ------------------------------------------------------------
236
236
 
237
- static extractErrorKeyOfJson(json, onlyIfUniqueError) {
237
+ static extractErrorKeyOfJson(json, onlyIfUniqueError=false) {
238
238
  if (typeof json == 'undefined' || json == null) {
239
239
  return null;
240
240
  }
@@ -243,7 +243,7 @@ class FormHelper {
243
243
  return json.error;
244
244
  }
245
245
 
246
- if (typeof onlyIfUniqueError != 'undefined' && onlyIfUniqueError && !json.length || json.length > 1) {
246
+ if (onlyIfUniqueError && !json.length || json.length > 1) {
247
247
  return null;
248
248
  }
249
249
 
@@ -267,18 +267,23 @@ class FormHelper {
267
267
  let errorLabels = [];
268
268
  for (let property in errors) {
269
269
  // console.log(property);
270
- if (typeof errors[property] != 'function') {
271
- if (typeof errors[property]['error_description'] === 'undefined') {
272
- errorLabels.push(errors[property]);
273
- } else {
274
- errorLabels.push(errors[property]['error_description']);
275
- }
270
+ if (typeof errors[property] == 'function') {
271
+ continue;
276
272
  }
273
+ if (typeof errors[property]['error_description'] !== 'undefined') {
274
+ errorLabels.push(errors[property]['error_description']);
275
+ continue;
276
+ }
277
+ if (Array.isArray(errors[property]) && errors[property].length === 2) {
278
+ errorLabels.push(errors[property][1]);
279
+ continue;
280
+ }
281
+ errorLabels.push(errors[property]);
277
282
  }
278
283
  return errorLabels.removeEmptyValues().map(errorLabel => '<span>' + errorLabel + '</span>').join('<br/>');
279
284
  }
280
285
 
281
- static displayFormErrors(form, btnSubmit, errors, errorWrapperDiv) {
286
+ static displayFormErrors(form, btnSubmit, errors, errorWrapperDiv=null) {
282
287
  this.displayFormErrorsFromText(form, this.getFormErrorText(errors), errorWrapperDiv);
283
288
  if (btnSubmit != null) {
284
289
  FormHelper.buttonLoader(btnSubmit, 'reset');
@@ -290,10 +295,10 @@ class FormHelper {
290
295
  }
291
296
  }
292
297
 
293
- static displayFormErrorsFromText(form, errorLabels, errorWrapperDiv) {
298
+ static displayFormErrorsFromText(form, errorLabels, errorWrapperDiv=null) {
294
299
  let errorDiv = '<div class="alert alert-danger form_errors">'+errorLabels+'</div>';
295
300
 
296
- if (typeof errorWrapperDiv != 'undefined' && errorWrapperDiv != null) {
301
+ if (null != errorWrapperDiv) {
297
302
  errorWrapperDiv.append(errorDiv);
298
303
  return;
299
304
  }
package/http_client.js CHANGED
@@ -156,6 +156,10 @@ class HTTPClient {
156
156
  }
157
157
 
158
158
  static logRequestFailure(response, json) {
159
+ if (null == response) {
160
+ console.error('Request failure : network error.');
161
+ return;
162
+ }
159
163
  console.error('Request failure. Status: '+response.statusText+' ; HTTP Code : '+response.status, json);
160
164
  }
161
165
  static logJqueryRequestFailure(jqxhr, status, errorThrown) {
@@ -222,18 +226,20 @@ class HTTPClient {
222
226
  data = null;
223
227
  }
224
228
 
225
- const requestOptions = {
226
- method: method,
227
- headers: headers,
228
- body: body,
229
- mode: 'cors',
230
- cache: 'no-cache'
231
- }
232
-
233
- const response = await fetch(url, requestOptions);
234
-
229
+ let response = null;
235
230
  let jsonData = {};
236
231
  try {
232
+ const requestOptions = {
233
+ method: method,
234
+ headers: headers,
235
+ body: body,
236
+ mode: 'cors',
237
+ cache: 'no-cache'
238
+ }
239
+
240
+ // On met le fetch dans un try catch pour détecter les erreurs de connexion réseau (si pas de connexion, une exception est déclenchée par fetch)
241
+ response = await fetch(url, requestOptions);
242
+
237
243
  if (response.status !== 204 && response.statusText !== 'No Content') {
238
244
  jsonData = await response.json();
239
245
  }
@@ -309,16 +315,19 @@ class HTTPClient {
309
315
  data = null;
310
316
  }
311
317
 
312
- const requestOptions = {
313
- method: method,
314
- headers: headers,
315
- body: body,
316
- mode: 'cors',
317
- cache: 'no-cache'
318
- }
319
-
320
- const response = await fetch(url, requestOptions);
318
+ let response = null;
321
319
  try {
320
+ const requestOptions = {
321
+ method: method,
322
+ headers: headers,
323
+ body: body,
324
+ mode: 'cors',
325
+ cache: 'no-cache'
326
+ }
327
+
328
+ // On met le fetch dans un try catch pour détecter les erreurs de connexion réseau (si pas de connexion, une exception est déclenchée par fetch)
329
+ response = await fetch(url, requestOptions);
330
+
322
331
  if (response.status === 401 && response.statusText === 'Expired JWT Token') {
323
332
  HTTPClient.refreshToken(() => HTTPClient.requestBlob(method, url, data, successCallback, errorCallback, completeCallback, additionalHeaders), errorCallback);
324
333
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.55",
3
+ "version": "1.1.57",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -10,7 +10,6 @@
10
10
  "license": "ISC",
11
11
  "description": "",
12
12
  "dependencies": {
13
- "ilib": "^14.16.0",
14
- "npm": "^10.2.3"
13
+ "ilib": "^14.16.0"
15
14
  }
16
15
  }