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(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.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
- 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
+ /**
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
- 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;
1699
+ }
1700
+ this.alert.addRange(AlertType.Danger, errorMessages);
1676
1701
  }
1677
- }
1678
- //return throwError('Error! please try again later.');
1679
- return of(result);
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 });