zek 14.2.70 → 14.2.72
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/fesm2020/zek.mjs
CHANGED
|
@@ -1585,12 +1585,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImpor
|
|
|
1585
1585
|
|
|
1586
1586
|
/** Handles HttpClient errors */
|
|
1587
1587
|
class HttpErrorHandler {
|
|
1588
|
-
constructor(
|
|
1589
|
-
this.
|
|
1590
|
-
this.
|
|
1588
|
+
constructor(alert, translate, router) {
|
|
1589
|
+
this.alert = alert;
|
|
1590
|
+
this.translate = translate;
|
|
1591
1591
|
this.router = router;
|
|
1592
1592
|
/** Create curried handleError function that already knows the service name */
|
|
1593
1593
|
this.createHandleError = (serviceName = '') => (operation = 'operation', result = {}, show = true) => this.handleError(serviceName, operation, result, show);
|
|
1594
|
+
this.createHandleErrorResult = (serviceName = '') => (operation = 'operation', show = true) => this.handleErrorResult(serviceName, operation, show);
|
|
1594
1595
|
}
|
|
1595
1596
|
/**
|
|
1596
1597
|
* Returns a function that handles Http operation failures.
|
|
@@ -1598,86 +1599,126 @@ class HttpErrorHandler {
|
|
|
1598
1599
|
* @param serviceName = name of the data service that attempted the operation
|
|
1599
1600
|
* @param operation - name of the operation that failed
|
|
1600
1601
|
* @param result - optional value to return as the observable result
|
|
1602
|
+
* @param show - optional value to show error
|
|
1601
1603
|
*/
|
|
1602
1604
|
handleError(serviceName = '', operation = 'operation', result = {}, show) {
|
|
1603
1605
|
return (response) => {
|
|
1604
1606
|
console.error(response);
|
|
1605
1607
|
if (show) {
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1608
|
+
this.showError(serviceName, operation, response);
|
|
1609
|
+
}
|
|
1610
|
+
//return throwError('Error! please try again later.');
|
|
1611
|
+
return of(result);
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Returns a function that handles Http operation failures.
|
|
1616
|
+
* This error handler lets the app continue to run as if no error occurred.
|
|
1617
|
+
* @param serviceName = name of the data service that attempted the operation
|
|
1618
|
+
* @param operation - name of the operation that failed
|
|
1619
|
+
* @param show - optional value to show error
|
|
1620
|
+
*/
|
|
1621
|
+
handleErrorResult(serviceName = '', operation = 'operation', show) {
|
|
1622
|
+
return (response) => {
|
|
1623
|
+
console.error(response);
|
|
1624
|
+
if (show) {
|
|
1625
|
+
this.showError(serviceName, operation, response);
|
|
1626
|
+
}
|
|
1627
|
+
let error;
|
|
1628
|
+
if (typeof response.error === 'string' && response.error[0] === '{') {
|
|
1629
|
+
error = JSON.parse(response.error);
|
|
1630
|
+
}
|
|
1631
|
+
else {
|
|
1632
|
+
error = response.error;
|
|
1633
|
+
}
|
|
1634
|
+
let result;
|
|
1635
|
+
if (error instanceof ErrorEvent) {
|
|
1636
|
+
result = { '': [response.error.message] };
|
|
1637
|
+
}
|
|
1638
|
+
if (typeof error === 'string') {
|
|
1639
|
+
result = { '': [response.error] };
|
|
1640
|
+
}
|
|
1641
|
+
else if (typeof error === 'object') {
|
|
1642
|
+
const errors = error.traceId || error.success === false
|
|
1643
|
+
? error.errors
|
|
1644
|
+
: error;
|
|
1645
|
+
result = errors;
|
|
1646
|
+
}
|
|
1647
|
+
return of(result);
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
showError(serviceName, operation, response) {
|
|
1651
|
+
switch (response.status) {
|
|
1652
|
+
case 0: //No Connection
|
|
1653
|
+
this.alert.error(`Can't connect to api server.`);
|
|
1654
|
+
break;
|
|
1655
|
+
case 400: //Bad Request
|
|
1656
|
+
let error;
|
|
1657
|
+
if (typeof response.error === 'string' && response.error[0] === '{') {
|
|
1658
|
+
error = JSON.parse(response.error);
|
|
1659
|
+
}
|
|
1660
|
+
else {
|
|
1661
|
+
error = response.error;
|
|
1662
|
+
}
|
|
1663
|
+
if (error instanceof ErrorEvent) {
|
|
1664
|
+
this.alert.error(`${serviceName}: ${operation} failed: ${response.error.message}`);
|
|
1665
|
+
}
|
|
1666
|
+
if (typeof error === 'string') {
|
|
1667
|
+
this.alert.error(response.error);
|
|
1668
|
+
}
|
|
1669
|
+
else if (typeof error === 'object') {
|
|
1670
|
+
const errors = error.traceId || error.success === false
|
|
1671
|
+
? error.errors
|
|
1672
|
+
: error;
|
|
1673
|
+
const errorMessages = [];
|
|
1674
|
+
const properties = Object.getOwnPropertyNames(errors);
|
|
1675
|
+
for (let property of properties) {
|
|
1676
|
+
const messages = errors[property];
|
|
1677
|
+
if (messages instanceof Array) {
|
|
1678
|
+
for (let message of messages) {
|
|
1679
|
+
const messageKey = `Validation.${message}`;
|
|
1680
|
+
let translatedMessage = this.translate.instant(messageKey);
|
|
1681
|
+
// if translation not found then use message
|
|
1682
|
+
if (messageKey == translatedMessage) {
|
|
1683
|
+
translatedMessage = message;
|
|
1684
|
+
}
|
|
1685
|
+
if (property) {
|
|
1686
|
+
const propertyKey = `Fields.${property}`;
|
|
1687
|
+
let translatedProperty = this.translate.instant(`Fields.${property}`);
|
|
1688
|
+
// if translation not found then use property
|
|
1689
|
+
if (propertyKey == translatedProperty) {
|
|
1690
|
+
translatedProperty = property;
|
|
1652
1691
|
}
|
|
1692
|
+
errorMessages.push(translatedProperty + ' - ' + translatedMessage);
|
|
1693
|
+
}
|
|
1694
|
+
else {
|
|
1695
|
+
errorMessages.push(translatedMessage);
|
|
1653
1696
|
}
|
|
1654
1697
|
}
|
|
1655
|
-
this.alertService.addRange(AlertType.Danger, errorMessages);
|
|
1656
1698
|
}
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
this.alertService.error('Unauthorized');
|
|
1660
|
-
this.router.navigate(['/login']);
|
|
1661
|
-
break;
|
|
1662
|
-
case 403: //Forbidden
|
|
1663
|
-
this.alertService.error('Forbidden');
|
|
1664
|
-
break;
|
|
1665
|
-
case 404: //Not Found
|
|
1666
|
-
this.alertService.error('Not Found');
|
|
1667
|
-
break;
|
|
1668
|
-
case 402: //Payment Required
|
|
1669
|
-
this.alertService.error('License Payment Required');
|
|
1670
|
-
break;
|
|
1671
|
-
case 500: //Internal Server Error
|
|
1672
|
-
this.alertService.error('Internal Server Error');
|
|
1673
|
-
break;
|
|
1674
|
-
default:
|
|
1675
|
-
break;
|
|
1699
|
+
}
|
|
1700
|
+
this.alert.addRange(AlertType.Danger, errorMessages);
|
|
1676
1701
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1702
|
+
break;
|
|
1703
|
+
case 401: //Unauthorized
|
|
1704
|
+
this.alert.error('Unauthorized');
|
|
1705
|
+
this.router.navigate(['/login']);
|
|
1706
|
+
break;
|
|
1707
|
+
case 403: //Forbidden
|
|
1708
|
+
this.alert.error('Forbidden');
|
|
1709
|
+
break;
|
|
1710
|
+
case 404: //Not Found
|
|
1711
|
+
this.alert.error('Not Found');
|
|
1712
|
+
break;
|
|
1713
|
+
case 402: //Payment Required
|
|
1714
|
+
this.alert.error('License Payment Required');
|
|
1715
|
+
break;
|
|
1716
|
+
case 500: //Internal Server Error
|
|
1717
|
+
this.alert.error('Internal Server Error');
|
|
1718
|
+
break;
|
|
1719
|
+
default:
|
|
1720
|
+
break;
|
|
1721
|
+
}
|
|
1681
1722
|
}
|
|
1682
1723
|
}
|
|
1683
1724
|
HttpErrorHandler.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: HttpErrorHandler, deps: [{ token: AlertService }, { token: i1$1.TranslateService }, { token: i1.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|