@esfaenza/httpservice 11.2.45 → 11.2.47
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/bundles/esfaenza-httpservice.umd.js +76 -75
- package/bundles/esfaenza-httpservice.umd.js.map +1 -1
- package/bundles/esfaenza-httpservice.umd.min.js +2 -2
- package/bundles/esfaenza-httpservice.umd.min.js.map +1 -1
- package/esm2015/lib/httpservice.service.js +79 -78
- package/fesm2015/esfaenza-httpservice.js +78 -77
- package/fesm2015/esfaenza-httpservice.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,8 +3,8 @@ import { HttpEventType, HttpHeaders, HttpErrorResponse, HttpClient } from '@angu
|
|
|
3
3
|
import { InjectionToken, Injectable, Inject, Optional, NgModule } from '@angular/core';
|
|
4
4
|
import { CacheService } from '@esfaenza/preferences';
|
|
5
5
|
import { UtilityService } from '@esfaenza/extensions';
|
|
6
|
-
import { delay, finalize, map, catchError, scan } from 'rxjs/operators';
|
|
7
|
-
import { forkJoin, of, throwError, Observable } from 'rxjs';
|
|
6
|
+
import { concatMap, delay, finalize, map, catchError, scan } from 'rxjs/operators';
|
|
7
|
+
import { forkJoin, from, of, throwError, Observable } from 'rxjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Dizionario di invalidazioni delle chiamate HTTP
|
|
@@ -232,25 +232,27 @@ class HTTPService {
|
|
|
232
232
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
233
233
|
*/
|
|
234
234
|
get(url, params = null, transaction = "", succesfulResultMandatory = true, errorCallback = null) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(transaction), params: params });
|
|
242
|
-
return httpCall.pipe(map((res) => {
|
|
243
|
-
let responseItem = res;
|
|
244
|
-
if (cachedInfos.cache) {
|
|
245
|
-
this.cacheResponse(this.utisExts.deepClone(responseItem), cachedInfos);
|
|
246
|
-
this.log(this.loc("Cached result for") + " " + url);
|
|
235
|
+
// TODO provare e testare
|
|
236
|
+
return from(this.defaultStartCall(url)).pipe(concatMap((myGuid) => {
|
|
237
|
+
let cachedInfos = this.tryGetCacheInformations(url, params);
|
|
238
|
+
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
239
|
+
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
240
|
+
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
247
241
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
242
|
+
var httpCall = this.http.get(cachedInfos.finalUrl, { headers: this.getHeaders(transaction), params: params });
|
|
243
|
+
return httpCall.pipe(map((res) => {
|
|
244
|
+
let responseItem = res;
|
|
245
|
+
if (cachedInfos.cache) {
|
|
246
|
+
this.cacheResponse(this.utisExts.deepClone(responseItem), cachedInfos);
|
|
247
|
+
this.log(this.loc("Cached result for") + " " + url);
|
|
248
|
+
}
|
|
249
|
+
return responseItem;
|
|
250
|
+
}), catchError((err, caught) => {
|
|
251
|
+
if (errorCallback)
|
|
252
|
+
errorCallback();
|
|
253
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
254
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid, cachedInfos); }));
|
|
255
|
+
}));
|
|
254
256
|
}
|
|
255
257
|
/**
|
|
256
258
|
* Esecuzione di una GET HTTP con eventualmente la gestione della cache qualora la chiamata termini con la convenzione "#cache"
|
|
@@ -268,24 +270,25 @@ class HTTPService {
|
|
|
268
270
|
* @returns {Observable<Blob | ArrayBuffer>} Observable che contiene il risultato della chiamata
|
|
269
271
|
*/
|
|
270
272
|
getRaw(url, params = null, type = "arraybuffer", transaction = "", succesfulResultMandatory = true, errorCallback = null) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(transaction), params: params });
|
|
278
|
-
return httpCall.pipe(map((blob) => {
|
|
279
|
-
if (cachedInfos.cache) {
|
|
280
|
-
this.cacheResponse(blob, cachedInfos);
|
|
281
|
-
this.log(this.loc("Cached result for") + " " + url);
|
|
273
|
+
return from(this.defaultStartCall(url)).pipe(concatMap((myGuid) => {
|
|
274
|
+
let cachedInfos = this.tryGetCacheInformations(url, params);
|
|
275
|
+
if (cachedInfos.cache && cachedInfos.cacheItem) {
|
|
276
|
+
this.log(this.loc("Result for") + " " + url + " " + this.loc("retrieved from cache"));
|
|
277
|
+
return of(cachedInfos.cacheItem).pipe(delay(0), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
282
278
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
279
|
+
var httpCall = this.http.get(cachedInfos.finalUrl, { responseType: type, headers: this.getHeaders(transaction), params: params });
|
|
280
|
+
return httpCall.pipe(map((blob) => {
|
|
281
|
+
if (cachedInfos.cache) {
|
|
282
|
+
this.cacheResponse(blob, cachedInfos);
|
|
283
|
+
this.log(this.loc("Cached result for") + " " + url);
|
|
284
|
+
}
|
|
285
|
+
return blob;
|
|
286
|
+
}), catchError((err, caught) => {
|
|
287
|
+
if (errorCallback)
|
|
288
|
+
errorCallback();
|
|
289
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
290
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid, cachedInfos); }));
|
|
291
|
+
}));
|
|
289
292
|
}
|
|
290
293
|
/**
|
|
291
294
|
* Esecuzione di una POST HTTP
|
|
@@ -300,14 +303,12 @@ class HTTPService {
|
|
|
300
303
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
301
304
|
*/
|
|
302
305
|
post(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
})
|
|
309
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
310
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
306
|
+
return from(this.defaultStartCall(url)).pipe(concatMap((myGuid) => {
|
|
307
|
+
var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
308
|
+
return httpCall.pipe(catchError((err, caught) => {
|
|
309
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
310
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
311
|
+
}));
|
|
311
312
|
}
|
|
312
313
|
/**
|
|
313
314
|
* Esecuzione di una DELETE HTTP
|
|
@@ -321,14 +322,12 @@ class HTTPService {
|
|
|
321
322
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
322
323
|
*/
|
|
323
324
|
delete(url, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
})
|
|
330
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
331
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
325
|
+
return from(this.defaultStartCall(url)).pipe(concatMap((myGuid) => {
|
|
326
|
+
var httpCall = this.http.delete(url, { headers: this.getHeaders(transaction), params: params });
|
|
327
|
+
return httpCall.pipe(catchError((err, caught) => {
|
|
328
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
329
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
330
|
+
}));
|
|
332
331
|
}
|
|
333
332
|
/**
|
|
334
333
|
* Esecuzione di una PUT HTTP
|
|
@@ -343,14 +342,12 @@ class HTTPService {
|
|
|
343
342
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
344
343
|
*/
|
|
345
344
|
put(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
})
|
|
352
|
-
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
353
|
-
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
345
|
+
return from(this.defaultStartCall(url)).pipe(concatMap((myGuid) => {
|
|
346
|
+
var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
347
|
+
return httpCall.pipe(catchError((err, caught) => {
|
|
348
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
349
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
350
|
+
}));
|
|
354
351
|
}
|
|
355
352
|
/**
|
|
356
353
|
* Esecuzione di una POST HTTP
|
|
@@ -364,11 +361,12 @@ class HTTPService {
|
|
|
364
361
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
365
362
|
*/
|
|
366
363
|
postwithFiles(url, bodyData, fileArrayOrFile) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
364
|
+
return from(this.defaultStartCall(url)).pipe(concatMap((myGuid) => {
|
|
365
|
+
var formData = this.getFilesFormData(fileArrayOrFile);
|
|
366
|
+
formData.append("body", JSON.stringify(bodyData));
|
|
367
|
+
var httpCall = this.http.post(url, formData, { headers: this.getHeaders(null, true, null, null) });
|
|
368
|
+
return httpCall.pipe(catchError((err, caught) => { return this.registerErrorAndReturnEmptyObservable(err, myGuid); }), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
369
|
+
}));
|
|
372
370
|
}
|
|
373
371
|
/**
|
|
374
372
|
* Esecuzione di una POST HTTP
|
|
@@ -532,17 +530,20 @@ class HTTPService {
|
|
|
532
530
|
*/
|
|
533
531
|
tryFinalizeByGuid(guid, cacheInfos) {
|
|
534
532
|
return __awaiter(this, void 0, void 0, function* () {
|
|
535
|
-
this.log(this.loc("Finalizing call") + " " + guid + " " + this.loc("with status") + ": " + (this.callStatus[guid].success ? this.loc('Success') : this.loc('Failure')));
|
|
536
|
-
//
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
this.LastThreeCompletedCalls.
|
|
544
|
-
|
|
545
|
-
|
|
533
|
+
this.log(this.loc("Finalizing call") + " " + guid + " " + this.loc("with status") + ": " + (!this.callStatus[guid] ? 'Unknown' : this.callStatus[guid].success ? this.loc('Success') : this.loc('Failure')));
|
|
534
|
+
// TODO: Perdere 3-4 ore per capire perché ogni tanto arriva null in casi pesanti di Observable spammati a random
|
|
535
|
+
if (this.callStatus[guid]) {
|
|
536
|
+
// Alla prima chiamata buona, significa che almeno il login ce l'ho. Posso mettermi in modalità redirectInProgress false
|
|
537
|
+
// e riiniziare a valutare errori di javashit
|
|
538
|
+
if (this.callStatus[guid].success && this.ExtensionsImpl.readRedirectionStatus())
|
|
539
|
+
this.ExtensionsImpl.writeRedirectionStatus(false);
|
|
540
|
+
// Aggiungo la chiamata alla lista delle ultime 3 completate
|
|
541
|
+
this.LastThreeCompletedCalls.unshift(this.callStatus[guid].url);
|
|
542
|
+
if (this.LastThreeCompletedCalls.length > 3)
|
|
543
|
+
this.LastThreeCompletedCalls.pop();
|
|
544
|
+
// In ogni caso questa posso rimuoverla
|
|
545
|
+
delete this.callStatus[guid];
|
|
546
|
+
}
|
|
546
547
|
// Se vengo da una chiamata che ha aggiornato la cache a timer o globale marco il fatto che quella cache dev'essere aggiornata
|
|
547
548
|
if (cacheInfos && cacheInfos.cache) {
|
|
548
549
|
this.PersistTimedCacheASAP = this.PersistTimedCacheASAP || !!cacheInfos.cacheTime;
|