zek 14.2.70 → 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/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(alertService, translateService, router) {
1589
- this.alertService = alertService;
1590
- this.translateService = translateService;
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.createHandleErrorJson = (serviceName = '') => (operation = 'operation', show = true) => this.handleErrorJson(serviceName, operation, show);
1594
1595
  }
1595
1596
  /**
1596
1597
  * Returns a function that handles Http operation failures.
@@ -1598,84 +1599,124 @@ 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
- switch (response.status) {
1607
- case 0: //No Connection
1608
- this.alertService.error(`Can't connect to api server.`);
1609
- break;
1610
- case 400: //Bad Request
1611
- let error;
1612
- if (typeof response.error === 'string' && response.error[0] === '{') {
1613
- error = JSON.parse(response.error);
1614
- }
1615
- else {
1616
- error = response.error;
1617
- }
1618
- if (error instanceof ErrorEvent) {
1619
- this.alertService.error(`${serviceName}: ${operation} failed: ${response.error.message}`);
1620
- }
1621
- if (error === 'string') {
1622
- this.alertService.error(response.error);
1623
- }
1624
- else if (error instanceof Object) {
1625
- const errors = error.traceId || error.success === false
1626
- ? error.errors
1627
- : error;
1628
- const errorMessages = [];
1629
- const properties = Object.getOwnPropertyNames(errors);
1630
- for (let property of properties) {
1631
- const messages = errors[property];
1632
- if (messages instanceof Array) {
1633
- for (let message of messages) {
1634
- const messageKey = `Validation.${message}`;
1635
- let translatedMessage = this.translateService.instant(messageKey);
1636
- // if translation not found then use message
1637
- if (messageKey == translatedMessage) {
1638
- translatedMessage = message;
1639
- }
1640
- if (property) {
1641
- const propertyKey = `Fields.${property}`;
1642
- let translatedProperty = this.translateService.instant(`Fields.${property}`);
1643
- // if translation not found then use property
1644
- if (propertyKey == translatedProperty) {
1645
- translatedProperty = property;
1646
- }
1647
- errorMessages.push(translatedProperty + ' - ' + translatedMessage);
1648
- }
1649
- else {
1650
- errorMessages.push(translatedMessage);
1651
- }
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;
1652
1655
  }
1656
+ errorMessages.push(translatedProperty + ' - ' + translatedMessage);
1657
+ }
1658
+ else {
1659
+ errorMessages.push(translatedMessage);
1653
1660
  }
1654
1661
  }
1655
- this.alertService.addRange(AlertType.Danger, errorMessages);
1656
1662
  }
1657
- break;
1658
- case 401: //Unauthorized
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;
1663
+ }
1664
+ this.alert.addRange(AlertType.Danger, errorMessages);
1676
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;
1677
1719
  }
1678
- //return throwError('Error! please try again later.');
1679
1720
  return of(result);
1680
1721
  };
1681
1722
  }