@osimatic/helpers-js 1.4.22 → 1.4.23

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.
Files changed (2) hide show
  1. package/http_client.js +19 -4
  2. package/package.json +1 -1
package/http_client.js CHANGED
@@ -289,7 +289,14 @@ class HTTPClient {
289
289
 
290
290
  static download(method, url, data, errorCallback=null, completeCallback=null, additionalHeaders={}) {
291
291
  HTTPClient.requestBlob(method, url, data,
292
- (blobData, response) => File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition')),
292
+ (blobData, response) => {
293
+ const contentType = response.headers.get('content-type');
294
+ // Si la réponse est du JSON, on ne télécharge pas de fichier
295
+ if (contentType && contentType.includes('application/json')) {
296
+ return;
297
+ }
298
+ File.download(blobData, contentType, response.headers.get('content-disposition'));
299
+ },
293
300
  errorCallback,
294
301
  completeCallback,
295
302
  additionalHeaders
@@ -346,9 +353,17 @@ class HTTPClient {
346
353
  }
347
354
 
348
355
  if (response.ok) {
349
- const blobData = await response.blob();
350
- if (typeof successCallback == 'function') {
351
- successCallback(blobData, response);
356
+ if (response.headers.get('Content-Type') === 'application/json') {
357
+ const json = await response.json();
358
+ if (typeof successCallback == 'function') {
359
+ successCallback(json, response);
360
+ }
361
+ }
362
+ else {
363
+ const blobData = await response.blob();
364
+ if (typeof successCallback == 'function') {
365
+ successCallback(blobData, response);
366
+ }
352
367
  }
353
368
  }
354
369
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.4.22",
3
+ "version": "1.4.23",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"