zek 14.2.69 → 14.2.71
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/esm2020/lib/services/auth.service.mjs +13 -7
- package/esm2020/lib/services/http-error-handler.service.mjs +112 -71
- package/fesm2015/zek.mjs +123 -76
- package/fesm2015/zek.mjs.map +1 -1
- package/fesm2020/zek.mjs +123 -76
- package/fesm2020/zek.mjs.map +1 -1
- package/lib/services/auth.service.d.ts +2 -1
- package/lib/services/http-error-handler.service.d.ts +15 -3
- package/package.json +1 -1
package/fesm2020/zek.mjs
CHANGED
|
@@ -1116,7 +1116,7 @@ class UrlHelper {
|
|
|
1116
1116
|
class AuthService {
|
|
1117
1117
|
constructor() {
|
|
1118
1118
|
this._isInitialized = false;
|
|
1119
|
-
this.
|
|
1119
|
+
this._oldValue = false;
|
|
1120
1120
|
this._user = null;
|
|
1121
1121
|
}
|
|
1122
1122
|
get user() {
|
|
@@ -1166,11 +1166,12 @@ class AuthService {
|
|
|
1166
1166
|
isAuthenticated() {
|
|
1167
1167
|
let expired = this.getExpired() || new Date(0); // if getExpired is null return min JS date
|
|
1168
1168
|
const newValue = new Date() < expired;
|
|
1169
|
-
if (this.
|
|
1170
|
-
this.
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1169
|
+
if (this._oldValue !== newValue) {
|
|
1170
|
+
this._oldValue = newValue;
|
|
1171
|
+
this.emitOnSignedIn();
|
|
1172
|
+
// if (this._onSignedInSubject) {
|
|
1173
|
+
// this._onSignedInSubject.next(newValue);
|
|
1174
|
+
// }
|
|
1174
1175
|
//if user is signed in and expired we need to logout (remove from localStorage)
|
|
1175
1176
|
if (!newValue) {
|
|
1176
1177
|
this.logout();
|
|
@@ -1179,6 +1180,11 @@ class AuthService {
|
|
|
1179
1180
|
}
|
|
1180
1181
|
return newValue;
|
|
1181
1182
|
}
|
|
1183
|
+
emitOnSignedIn() {
|
|
1184
|
+
if (this._onSignedInSubject) {
|
|
1185
|
+
this._onSignedInSubject.next(this._oldValue);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1182
1188
|
get onSignedIn() {
|
|
1183
1189
|
if (!this._onSignedInSubject) {
|
|
1184
1190
|
this._onSignedInSubject = new BehaviorSubject(false);
|
|
@@ -1579,12 +1585,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImpor
|
|
|
1579
1585
|
|
|
1580
1586
|
/** Handles HttpClient errors */
|
|
1581
1587
|
class HttpErrorHandler {
|
|
1582
|
-
constructor(
|
|
1583
|
-
this.
|
|
1584
|
-
this.
|
|
1588
|
+
constructor(alert, translate, router) {
|
|
1589
|
+
this.alert = alert;
|
|
1590
|
+
this.translate = translate;
|
|
1585
1591
|
this.router = router;
|
|
1586
1592
|
/** Create curried handleError function that already knows the service name */
|
|
1587
1593
|
this.createHandleError = (serviceName = '') => (operation = 'operation', result = {}, show = true) => this.handleError(serviceName, operation, result, show);
|
|
1594
|
+
this.createHandleErrorJson = (serviceName = '') => (operation = 'operation', show = true) => this.handleErrorJson(serviceName, operation, show);
|
|
1588
1595
|
}
|
|
1589
1596
|
/**
|
|
1590
1597
|
* Returns a function that handles Http operation failures.
|
|
@@ -1592,84 +1599,124 @@ class HttpErrorHandler {
|
|
|
1592
1599
|
* @param serviceName = name of the data service that attempted the operation
|
|
1593
1600
|
* @param operation - name of the operation that failed
|
|
1594
1601
|
* @param result - optional value to return as the observable result
|
|
1602
|
+
* @param show - optional value to show error
|
|
1595
1603
|
*/
|
|
1596
1604
|
handleError(serviceName = '', operation = 'operation', result = {}, show) {
|
|
1597
1605
|
return (response) => {
|
|
1598
1606
|
console.error(response);
|
|
1599
1607
|
if (show) {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
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
|
-
|
|
1608
|
+
this.showError(serviceName, operation, response);
|
|
1609
|
+
}
|
|
1610
|
+
//return throwError('Error! please try again later.');
|
|
1611
|
+
return of(result);
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
showError(serviceName, operation, response) {
|
|
1615
|
+
switch (response.status) {
|
|
1616
|
+
case 0: //No Connection
|
|
1617
|
+
this.alert.error(`Can't connect to api server.`);
|
|
1618
|
+
break;
|
|
1619
|
+
case 400: //Bad Request
|
|
1620
|
+
let error;
|
|
1621
|
+
if (typeof response.error === 'string' && response.error[0] === '{') {
|
|
1622
|
+
error = JSON.parse(response.error);
|
|
1623
|
+
}
|
|
1624
|
+
else {
|
|
1625
|
+
error = response.error;
|
|
1626
|
+
}
|
|
1627
|
+
if (error instanceof ErrorEvent) {
|
|
1628
|
+
this.alert.error(`${serviceName}: ${operation} failed: ${response.error.message}`);
|
|
1629
|
+
}
|
|
1630
|
+
if (typeof error === 'string') {
|
|
1631
|
+
this.alert.error(response.error);
|
|
1632
|
+
}
|
|
1633
|
+
else if (typeof error === 'object') {
|
|
1634
|
+
const errors = error.traceId || error.success === false
|
|
1635
|
+
? error.errors
|
|
1636
|
+
: error;
|
|
1637
|
+
const errorMessages = [];
|
|
1638
|
+
const properties = Object.getOwnPropertyNames(errors);
|
|
1639
|
+
for (let property of properties) {
|
|
1640
|
+
const messages = errors[property];
|
|
1641
|
+
if (messages instanceof Array) {
|
|
1642
|
+
for (let message of messages) {
|
|
1643
|
+
const messageKey = `Validation.${message}`;
|
|
1644
|
+
let translatedMessage = this.translate.instant(messageKey);
|
|
1645
|
+
// if translation not found then use message
|
|
1646
|
+
if (messageKey == translatedMessage) {
|
|
1647
|
+
translatedMessage = message;
|
|
1648
|
+
}
|
|
1649
|
+
if (property) {
|
|
1650
|
+
const propertyKey = `Fields.${property}`;
|
|
1651
|
+
let translatedProperty = this.translate.instant(`Fields.${property}`);
|
|
1652
|
+
// if translation not found then use property
|
|
1653
|
+
if (propertyKey == translatedProperty) {
|
|
1654
|
+
translatedProperty = property;
|
|
1646
1655
|
}
|
|
1656
|
+
errorMessages.push(translatedProperty + ' - ' + translatedMessage);
|
|
1657
|
+
}
|
|
1658
|
+
else {
|
|
1659
|
+
errorMessages.push(translatedMessage);
|
|
1647
1660
|
}
|
|
1648
1661
|
}
|
|
1649
|
-
this.alertService.addRange(AlertType.Danger, errorMessages);
|
|
1650
1662
|
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
this.alertService.error('Unauthorized');
|
|
1654
|
-
this.router.navigate(['/login']);
|
|
1655
|
-
break;
|
|
1656
|
-
case 403: //Forbidden
|
|
1657
|
-
this.alertService.error('Forbidden');
|
|
1658
|
-
break;
|
|
1659
|
-
case 404: //Not Found
|
|
1660
|
-
this.alertService.error('Not Found');
|
|
1661
|
-
break;
|
|
1662
|
-
case 402: //Payment Required
|
|
1663
|
-
this.alertService.error('License Payment Required');
|
|
1664
|
-
break;
|
|
1665
|
-
case 500: //Internal Server Error
|
|
1666
|
-
this.alertService.error('Internal Server Error');
|
|
1667
|
-
break;
|
|
1668
|
-
default:
|
|
1669
|
-
break;
|
|
1663
|
+
}
|
|
1664
|
+
this.alert.addRange(AlertType.Danger, errorMessages);
|
|
1670
1665
|
}
|
|
1666
|
+
break;
|
|
1667
|
+
case 401: //Unauthorized
|
|
1668
|
+
this.alert.error('Unauthorized');
|
|
1669
|
+
this.router.navigate(['/login']);
|
|
1670
|
+
break;
|
|
1671
|
+
case 403: //Forbidden
|
|
1672
|
+
this.alert.error('Forbidden');
|
|
1673
|
+
break;
|
|
1674
|
+
case 404: //Not Found
|
|
1675
|
+
this.alert.error('Not Found');
|
|
1676
|
+
break;
|
|
1677
|
+
case 402: //Payment Required
|
|
1678
|
+
this.alert.error('License Payment Required');
|
|
1679
|
+
break;
|
|
1680
|
+
case 500: //Internal Server Error
|
|
1681
|
+
this.alert.error('Internal Server Error');
|
|
1682
|
+
break;
|
|
1683
|
+
default:
|
|
1684
|
+
break;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* Returns a function that handles Http operation failures.
|
|
1689
|
+
* This error handler lets the app continue to run as if no error occurred.
|
|
1690
|
+
* @param serviceName = name of the data service that attempted the operation
|
|
1691
|
+
* @param operation - name of the operation that failed
|
|
1692
|
+
* @param show - optional value to show error
|
|
1693
|
+
*/
|
|
1694
|
+
handleErrorJson(serviceName = '', operation = 'operation', show) {
|
|
1695
|
+
return (response) => {
|
|
1696
|
+
console.error(response);
|
|
1697
|
+
if (show) {
|
|
1698
|
+
this.showError(serviceName, operation, response);
|
|
1699
|
+
}
|
|
1700
|
+
let error;
|
|
1701
|
+
if (typeof response.error === 'string' && response.error[0] === '{') {
|
|
1702
|
+
error = JSON.parse(response.error);
|
|
1703
|
+
}
|
|
1704
|
+
else {
|
|
1705
|
+
error = response.error;
|
|
1706
|
+
}
|
|
1707
|
+
let result;
|
|
1708
|
+
if (error instanceof ErrorEvent) {
|
|
1709
|
+
result = { '': [response.error.message] };
|
|
1710
|
+
}
|
|
1711
|
+
if (typeof error === 'string') {
|
|
1712
|
+
result = { '': [response.error] };
|
|
1713
|
+
}
|
|
1714
|
+
else if (typeof error === 'object') {
|
|
1715
|
+
const errors = error.traceId || error.success === false
|
|
1716
|
+
? error.errors
|
|
1717
|
+
: error;
|
|
1718
|
+
result = errors;
|
|
1671
1719
|
}
|
|
1672
|
-
//return throwError('Error! please try again later.');
|
|
1673
1720
|
return of(result);
|
|
1674
1721
|
};
|
|
1675
1722
|
}
|