@esfaenza/httpservice 12.2.16 → 12.2.20
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 +528 -67
- package/bundles/esfaenza-httpservice.umd.js.map +1 -1
- package/esfaenza-httpservice.metadata.json +1 -1
- package/esm2015/lib/config/HttpServiceExtensions.js +1 -1
- package/esm2015/lib/httpservice.service.js +193 -65
- package/esm2015/lib/httpservice.service.loc.js +3 -2
- package/fesm2015/esfaenza-httpservice.js +194 -66
- package/fesm2015/esfaenza-httpservice.js.map +1 -1
- package/lib/config/HttpServiceExtensions.d.ts +1 -1
- package/lib/httpservice.service.d.ts +69 -4
- package/lib/httpservice.service.loc.d.ts +4 -0
- package/package.json +3 -3
|
@@ -17,6 +17,7 @@ export const Loc = {
|
|
|
17
17
|
"redirecting to login": { "en-US": "redirecting to login", "it-IT": "redireziono al login", },
|
|
18
18
|
"Redirecting to Login, ignoring HTTP error on call": { "en-US": "Redirecting to Login, ignoring HTTP error on call", "it-IT": "Redireziono al login ignorando errori sulla chiamata", },
|
|
19
19
|
"Already Handling an error, ignoring HTTP error on call": { "en-US": "Already Handling an error, ignoring HTTP error on call", "it-IT": "sto già gestendo un errore, ignoro quello corrente per la chiamata HTTP", },
|
|
20
|
-
"Error 444 on call": { "en-US": "Error 444 on call", "it-IT": "Errore 444 su chiamata"
|
|
20
|
+
"Error 444 on call": { "en-US": "Error 444 on call", "it-IT": "Errore 444 su chiamata" },
|
|
21
|
+
"Resource not found": { "en-US": "Resource not found", "it-IT": "Risorsa non trovata" }
|
|
21
22
|
};
|
|
22
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
23
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaHR0cHNlcnZpY2Uuc2VydmljZS5sb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN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m9yIDQ0NCBvbiBjYWxsXCI6IHsgXCJlbi1VU1wiOiBcIkVycm9yIDQ0NCBvbiBjYWxsXCIsIFwiaXQtSVRcIjogXCJFcnJvcmUgNDQ0IHN1IGNoaWFtYXRhXCIgfSxcclxuICAgIFwiUmVzb3VyY2Ugbm90IGZvdW5kXCI6IHsgXCJlbi1VU1wiOiBcIlJlc291cmNlIG5vdCBmb3VuZFwiLCBcIml0LUlUXCI6IFwiUmlzb3JzYSBub24gdHJvdmF0YVwiIH1cclxufSJdfQ==
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { HttpEventType, HttpHeaders, HttpErrorResponse, HttpClient } from '@angular/common/http';
|
|
2
3
|
import { InjectionToken, Injectable, Inject, Optional, NgModule } from '@angular/core';
|
|
3
4
|
import { delay, finalize, map, catchError, scan } from 'rxjs/operators';
|
|
4
5
|
import { of, throwError, Observable } from 'rxjs';
|
|
@@ -130,10 +131,10 @@ const Loc = {
|
|
|
130
131
|
"redirecting to login": { "en-US": "redirecting to login", "it-IT": "redireziono al login", },
|
|
131
132
|
"Redirecting to Login, ignoring HTTP error on call": { "en-US": "Redirecting to Login, ignoring HTTP error on call", "it-IT": "Redireziono al login ignorando errori sulla chiamata", },
|
|
132
133
|
"Already Handling an error, ignoring HTTP error on call": { "en-US": "Already Handling an error, ignoring HTTP error on call", "it-IT": "sto già gestendo un errore, ignoro quello corrente per la chiamata HTTP", },
|
|
133
|
-
"Error 444 on call": { "en-US": "Error 444 on call", "it-IT": "Errore 444 su chiamata"
|
|
134
|
+
"Error 444 on call": { "en-US": "Error 444 on call", "it-IT": "Errore 444 su chiamata" },
|
|
135
|
+
"Resource not found": { "en-US": "Resource not found", "it-IT": "Risorsa non trovata" }
|
|
134
136
|
};
|
|
135
137
|
|
|
136
|
-
// Angular
|
|
137
138
|
/**
|
|
138
139
|
* Servizio utilizzato per effettuare qualsiasi tipo di chiamata HTTP dall'applicazione, gestisce errori e cache delle risposte nativamente e ne può essere
|
|
139
140
|
* esteso/modificato il comportamento implementando la classe di "hook" **IHttpServiceExtensions** e registrandola nel provider della classe **HttpServiceExtensions**
|
|
@@ -250,20 +251,63 @@ class HTTPService {
|
|
|
250
251
|
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
251
252
|
}
|
|
252
253
|
/**
|
|
253
|
-
* Esecuzione di una POST HTTP
|
|
254
|
-
*
|
|
254
|
+
* Esecuzione di una POST HTTP
|
|
255
255
|
*
|
|
256
256
|
* @param {string} url URL su cui effettuare la chiamata
|
|
257
257
|
* @param {any} bodyData DTO per la chiamata
|
|
258
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
259
|
+
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
260
|
+
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
261
|
+
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
262
|
+
*
|
|
263
|
+
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
264
|
+
*/
|
|
265
|
+
post(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
266
|
+
let myGuid = this.defaultStartCall(url);
|
|
267
|
+
var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
268
|
+
return httpCall.pipe(map((res) => {
|
|
269
|
+
let responseItem = res;
|
|
270
|
+
return responseItem;
|
|
271
|
+
}), catchError((err, caught) => {
|
|
272
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
273
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Esecuzione di una DELETE HTTP
|
|
277
|
+
*
|
|
278
|
+
* @param {string} url URL su cui effettuare la chiamata
|
|
279
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
258
280
|
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
259
281
|
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
260
282
|
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
261
283
|
*
|
|
262
284
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
263
285
|
*/
|
|
264
|
-
|
|
286
|
+
delete(url, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
265
287
|
let myGuid = this.defaultStartCall(url);
|
|
266
|
-
var httpCall = this.http.
|
|
288
|
+
var httpCall = this.http.delete(url, { headers: this.getHeaders(transaction), params: params });
|
|
289
|
+
return httpCall.pipe(map((res) => {
|
|
290
|
+
let responseItem = res;
|
|
291
|
+
return responseItem;
|
|
292
|
+
}), catchError((err, caught) => {
|
|
293
|
+
return !succesfulResultMandatory ? throwError(err) : this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
294
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); }));
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Esecuzione di una PUT HTTP
|
|
298
|
+
*
|
|
299
|
+
* @param {string} url URL su cui effettuare la chiamata
|
|
300
|
+
* @param {any} bodyData DTO per la chiamata
|
|
301
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
302
|
+
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
303
|
+
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
304
|
+
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
305
|
+
*
|
|
306
|
+
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
307
|
+
*/
|
|
308
|
+
put(url, bodyData, params = null, transaction = "", succesfulResultMandatory = true) {
|
|
309
|
+
let myGuid = this.defaultStartCall(url);
|
|
310
|
+
var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
267
311
|
return httpCall.pipe(map((res) => {
|
|
268
312
|
let responseItem = res;
|
|
269
313
|
return responseItem;
|
|
@@ -297,7 +341,7 @@ class HTTPService {
|
|
|
297
341
|
*
|
|
298
342
|
* @param {string} url URL su cui effettuare la chiamata
|
|
299
343
|
* @param {K} bodyData DTO per la chiamata
|
|
300
|
-
* @param {string} filename Nome del file che si sta richiedendo, rimane lato Frontend e serve per assegnare arbitrariamente un nome al file restituito
|
|
344
|
+
* @param {string} filename Nome del file che si sta richiedendo, rimane lato Frontend e serve per assegnare arbitrariamente un nome al file restituito, se vuoto viene utilizzata la Content-Disposition della risposta
|
|
301
345
|
* @param {Function} getFileCallback Callback a due parametri (url: string, filename: string) per gestire il risultato del file richiesto. **Utilizzare UtilityService.fileDownload** di @esfaenza/extensions
|
|
302
346
|
* @param {Function} afterGetFile Callback da chiamare dopo aver gestito la risposta del **getFileCallback**, in caso **handleError** fosse **false** verrà richiamato anche in caso di errore
|
|
303
347
|
* @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
|
|
@@ -309,12 +353,38 @@ class HTTPService {
|
|
|
309
353
|
afterGetFile();
|
|
310
354
|
return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
311
355
|
}), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
|
|
312
|
-
|
|
313
|
-
let retUrl = window.URL.createObjectURL(
|
|
314
|
-
let
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
356
|
+
var _a, _b, _c, _d;
|
|
357
|
+
let retUrl = window.URL.createObjectURL(response.body);
|
|
358
|
+
let fn = (_d = (_c = (_b = (_a = response.headers.get('content-disposition')) === null || _a === void 0 ? void 0 : _a.split(';')[1]) === null || _b === void 0 ? void 0 : _b.split('filename')[1]) === null || _c === void 0 ? void 0 : _c.split('=')[1]) === null || _d === void 0 ? void 0 : _d.trim().replace(/\"/g, '');
|
|
359
|
+
getFileCallback(retUrl, filename || fn);
|
|
360
|
+
if (afterGetFile)
|
|
361
|
+
afterGetFile();
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Esecuzione di una GET HTTP
|
|
366
|
+
*
|
|
367
|
+
* Casistica particolare in cui viene restituito un file gestito come ObjectURL il cui URL si può gestire dal parametro di callback **getFileCallback**.
|
|
368
|
+
* La chiamata non ha un tipo restituito in quanto il risultato dev'essere gestito attraverso la callback **getFileCallback**
|
|
369
|
+
*
|
|
370
|
+
* @param {string} url URL su cui effettuare la chiamata
|
|
371
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
372
|
+
* @param {string} filename Nome del file che si sta richiedendo, rimane lato Frontend e serve per assegnare arbitrariamente un nome al file restituito, se vuoto viene utilizzata la Content-Disposition della risposta
|
|
373
|
+
* @param {Function} getFileCallback Callback a due parametri (url: string, filename: string) per gestire il risultato del file richiesto. **Utilizzare UtilityService.fileDownload** di @esfaenza/extensions
|
|
374
|
+
* @param {Function} afterGetFile Callback da chiamare dopo aver gestito la risposta del **getFileCallback**, in caso **handleError** fosse **false** verrà richiamato anche in caso di errore
|
|
375
|
+
* @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
|
|
376
|
+
*/
|
|
377
|
+
getFile(url, params = null, filename, getFileCallback, afterGetFile = null, handleError = true) {
|
|
378
|
+
let myGuid = this.defaultStartCall(url);
|
|
379
|
+
this.http.get(url, { params: params, headers: this.getHeaders(), observe: 'response', responseType: "blob" }).pipe(catchError((err, caught) => {
|
|
380
|
+
if (afterGetFile && !handleError)
|
|
381
|
+
afterGetFile();
|
|
382
|
+
return this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
383
|
+
}), finalize(() => { this.tryFinalizeByGuid(myGuid); })).subscribe((response) => {
|
|
384
|
+
var _a, _b, _c, _d;
|
|
385
|
+
let retUrl = window.URL.createObjectURL(response.body);
|
|
386
|
+
let fn = (_d = (_c = (_b = (_a = response.headers.get('content-disposition')) === null || _a === void 0 ? void 0 : _a.split(';')[1]) === null || _b === void 0 ? void 0 : _b.split('filename')[1]) === null || _c === void 0 ? void 0 : _c.split('=')[1]) === null || _d === void 0 ? void 0 : _d.trim().replace(/\"/g, '');
|
|
387
|
+
getFileCallback(retUrl, filename || fn);
|
|
318
388
|
if (afterGetFile)
|
|
319
389
|
afterGetFile();
|
|
320
390
|
});
|
|
@@ -326,7 +396,7 @@ class HTTPService {
|
|
|
326
396
|
* @param {HttpParams} params Parametri della chiamata
|
|
327
397
|
*/
|
|
328
398
|
getFileNative(url, params = null) {
|
|
329
|
-
let finalUrl = url + "?" + params.toString();
|
|
399
|
+
let finalUrl = url + (params ? "?" + params.toString() : "");
|
|
330
400
|
window.location.href = finalUrl;
|
|
331
401
|
}
|
|
332
402
|
/**
|
|
@@ -481,61 +551,119 @@ class HTTPService {
|
|
|
481
551
|
* @param {string} guid Identificativo GUID della chiamata effettuata
|
|
482
552
|
*/
|
|
483
553
|
onError(res, guid) {
|
|
484
|
-
this
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
554
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
555
|
+
this.callStatus[guid] = false;
|
|
556
|
+
//Mi assicuro che tutti gli errori durante il redirect al login vengano ignorati
|
|
557
|
+
if (this.ExtensionsImpl.readRedirectingToLogin()) {
|
|
558
|
+
this.log(this.loc("Redirecting to Login, ignoring HTTP error on call") + " " + guid);
|
|
488
559
|
return;
|
|
489
560
|
}
|
|
490
|
-
|
|
491
|
-
this.ExtensionsImpl.
|
|
492
|
-
|
|
493
|
-
this.ExtensionsImpl.redirectToLogin();
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
//Mi assicuro che tutti gli errori durante il redirect al login vengano ignorati
|
|
497
|
-
if (this.ExtensionsImpl.readRedirectingToLogin()) {
|
|
498
|
-
this.log(this.loc("Redirecting to Login, ignoring HTTP error on call") + " " + guid);
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
//Mi assicuro che venga gestito un solo errore per volta
|
|
502
|
-
if (this.ExtensionsImpl.readHandlingErrorStatus()) {
|
|
503
|
-
this.log(this.loc("Already Handling an error, ignoring HTTP error on call") + " " + guid);
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
else
|
|
507
|
-
this.ExtensionsImpl.writeHandlingErrorStatus(true);
|
|
508
|
-
if (res.status == 0) {
|
|
509
|
-
if (res.statusText)
|
|
510
|
-
res.statusText = "Server Offline?" + " (" + res.statusText + ") ";
|
|
511
|
-
else
|
|
512
|
-
res.statusText = "Server Offline?";
|
|
513
|
-
}
|
|
514
|
-
var text = "";
|
|
515
|
-
if (res.error) {
|
|
516
|
-
var convertedError = res.error;
|
|
517
|
-
if (convertedError.error)
|
|
518
|
-
text = convertedError.error.message;
|
|
519
|
-
else
|
|
520
|
-
text = convertedError.toString();
|
|
521
|
-
}
|
|
522
|
-
else
|
|
523
|
-
text = res.statusText;
|
|
524
|
-
// 444: NotConfiguredException
|
|
525
|
-
if (res.status == 444) {
|
|
526
|
-
if (this.ExtensionsImpl.readRedirectionStatus()) {
|
|
527
|
-
this.log(this.loc("Error 444 on call") + " " + guid + " " + this.loc("with redirect already in progress. Ignoring this event"));
|
|
561
|
+
//Mi assicuro che venga gestito un solo errore per volta
|
|
562
|
+
if (this.ExtensionsImpl.readHandlingErrorStatus()) {
|
|
563
|
+
this.log(this.loc("Already Handling an error, ignoring HTTP error on call") + " " + guid);
|
|
528
564
|
return;
|
|
529
565
|
}
|
|
530
|
-
|
|
531
|
-
this.ExtensionsImpl.
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
566
|
+
else
|
|
567
|
+
this.ExtensionsImpl.writeHandlingErrorStatus(true);
|
|
568
|
+
let finalError = "";
|
|
569
|
+
let finalStatus = "";
|
|
570
|
+
if (this.isTypeError(res)) {
|
|
571
|
+
finalError = res.message;
|
|
572
|
+
finalStatus = "HTTP Service Internal Error";
|
|
573
|
+
}
|
|
574
|
+
else if (this.isHttpErrorResponse(res)) {
|
|
575
|
+
finalError = yield this.getHttpErrorText(res.error);
|
|
576
|
+
finalStatus = res.status.toString();
|
|
577
|
+
switch (res.status) {
|
|
578
|
+
// Unauthorized
|
|
579
|
+
case 401:
|
|
580
|
+
if (this.ExtensionsImpl.readRedirectionStatus()) {
|
|
581
|
+
this.log(this.loc("Error 401 on call") + " " + guid + " " + this.loc("with redirect already in progress. Ignoring this event"));
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
this.log(this.loc("Error 401 on call") + " " + guid + " " + this.loc("redirecting to login."));
|
|
585
|
+
this.ExtensionsImpl.writeRedirectionStatus(true);
|
|
586
|
+
this.ExtensionsImpl.writeRedirectingToLogin(true);
|
|
587
|
+
this.ExtensionsImpl.redirectToLogin();
|
|
588
|
+
return;
|
|
589
|
+
// Handled exception
|
|
590
|
+
case 400:
|
|
591
|
+
// No Permissions
|
|
592
|
+
case 403:
|
|
593
|
+
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
594
|
+
return;
|
|
595
|
+
// Not found
|
|
596
|
+
case 404:
|
|
597
|
+
this.ExtensionsImpl.handleBlockingException(res.status, this.loc("Resource not found"));
|
|
598
|
+
return;
|
|
599
|
+
// NotConfiguredException
|
|
600
|
+
case 444:
|
|
601
|
+
if (this.ExtensionsImpl.readRedirectionStatus())
|
|
602
|
+
this.log(this.loc("Error 444 on call") + " " + guid + " " + this.loc("with redirect already in progress. Ignoring this event"));
|
|
603
|
+
else if (!this.ExtensionsImpl.handleNotConfiguredException())
|
|
604
|
+
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
605
|
+
return;
|
|
606
|
+
case 0:
|
|
607
|
+
finalError = "Server might be offline" + (res.statusText ? " (" + res.statusText + ") " : "");
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
this.ExtensionsImpl.handleException(finalStatus, finalError);
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Dato un errore restituisce una promise con la stringa finale dell'errore in modo da poter fare un await
|
|
615
|
+
*
|
|
616
|
+
* @param {any} err Errore da controllare
|
|
617
|
+
*
|
|
618
|
+
* @returns {Promise<string>} Promise che risolve con la stringa finale dell'errore
|
|
619
|
+
*/
|
|
620
|
+
getHttpErrorText(err) {
|
|
621
|
+
// Se ho un Blob può essere o un CallResult o suppongo una semplice stringa,
|
|
622
|
+
// altrimenti potrebbe essere direttamente un CallResult, oppure una semplice stringa
|
|
623
|
+
return new Promise((resolve) => {
|
|
624
|
+
if (err instanceof Blob) {
|
|
625
|
+
let reader = new FileReader();
|
|
626
|
+
reader.onload = (e) => {
|
|
627
|
+
let errMsg = e.target.result;
|
|
628
|
+
let jsonerrMsg;
|
|
629
|
+
try {
|
|
630
|
+
jsonerrMsg = JSON.parse(errMsg);
|
|
631
|
+
}
|
|
632
|
+
catch (e) { }
|
|
633
|
+
return resolve(jsonerrMsg && this.isCallResult(jsonerrMsg) ? jsonerrMsg.error.message : errMsg);
|
|
634
|
+
};
|
|
635
|
+
reader.readAsText(err);
|
|
636
|
+
}
|
|
637
|
+
else if (this.isCallResult(err))
|
|
638
|
+
return resolve(err.error.message);
|
|
639
|
+
else
|
|
640
|
+
return resolve(err === null || err === void 0 ? void 0 : err.toString());
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Riconosce se l'oggetto è di tipo **CallResult** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
645
|
+
*
|
|
646
|
+
* @param {any} err Errore da controllare
|
|
647
|
+
*/
|
|
648
|
+
isCallResult(err) {
|
|
649
|
+
var _a;
|
|
650
|
+
return !!((_a = err === null || err === void 0 ? void 0 : err.error) === null || _a === void 0 ? void 0 : _a.message);
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Riconosce se l'errore è di tipo **HttpErrorResponse** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
654
|
+
*
|
|
655
|
+
* @param {any} err Errore da controllare
|
|
656
|
+
*/
|
|
657
|
+
isHttpErrorResponse(err) {
|
|
658
|
+
return err instanceof HttpErrorResponse;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Riconosce se l'errore è di tipo **TypeError** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
662
|
+
*
|
|
663
|
+
* @param {any} err Errore da controllare
|
|
664
|
+
*/
|
|
665
|
+
isTypeError(err) {
|
|
666
|
+
return err.name == "TypeError";
|
|
539
667
|
}
|
|
540
668
|
/**
|
|
541
669
|
* Come dice il nome, registra un errore e restituisce un Observable vuoto come risultato della chiamata
|