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