@osovitny/anatoly 3.19.5 → 3.19.7

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.
@@ -1911,10 +1911,15 @@ class AuthService extends ApiServiceBase {
1911
1911
  });
1912
1912
  }
1913
1913
  checkAndSetActiveAccount() {
1914
- let activeAccount = this.msalService.instance.getActiveAccount();
1915
- let accounts = this.msalService.instance.getAllAccounts();
1916
- if (!activeAccount && accounts.length > 0) {
1917
- this.msalService.instance.setActiveAccount(accounts[0]);
1914
+ try {
1915
+ let activeAccount = this.msalService.instance.getActiveAccount();
1916
+ let accounts = this.msalService.instance.getAllAccounts();
1917
+ if (!activeAccount && accounts.length > 0) {
1918
+ this.msalService.instance.setActiveAccount(accounts[0]);
1919
+ }
1920
+ }
1921
+ catch (error) {
1922
+ console.error("An error occurred: ", error);
1918
1923
  }
1919
1924
  }
1920
1925
  isPopup(popup) {
@@ -1940,8 +1945,13 @@ class AuthService extends ApiServiceBase {
1940
1945
  }
1941
1946
  // Public funcs
1942
1947
  getActiveAccount() {
1943
- this.checkAndSetActiveAccount();
1944
- return this.msalService.instance.getActiveAccount();
1948
+ try {
1949
+ this.checkAndSetActiveAccount();
1950
+ return this.msalService.instance.getActiveAccount();
1951
+ }
1952
+ catch (error) {
1953
+ console.error("An error occurred: ", error);
1954
+ }
1945
1955
  }
1946
1956
  getUserEmail() {
1947
1957
  let user = this.appContext.user;
@@ -2003,21 +2013,26 @@ class AuthService extends ApiServiceBase {
2003
2013
  }));
2004
2014
  }
2005
2015
  //2. if isUserAuthenticated
2006
- let activeAccount = this.getActiveAccount();
2007
- if (activeAccount) {
2008
- let silentRequest = {
2009
- scopes: MSALUtils.getApiScopes(),
2010
- account: activeAccount
2011
- };
2012
- return this.msalService.acquireTokenSilent(silentRequest).pipe(map$1(response => {
2013
- return response.accessToken;
2014
- }), catchError(error => {
2015
- console.log("Silent token acquisition fails.");
2016
- if (error instanceof InteractionRequiredAuthError) {
2017
- return this.acquireToken();
2018
- }
2019
- return of(null);
2020
- }));
2016
+ try {
2017
+ let activeAccount = this.getActiveAccount();
2018
+ if (activeAccount) {
2019
+ let silentRequest = {
2020
+ scopes: MSALUtils.getApiScopes(),
2021
+ account: activeAccount
2022
+ };
2023
+ return this.msalService.acquireTokenSilent(silentRequest).pipe(map$1(response => {
2024
+ return response.accessToken;
2025
+ }), catchError(error => {
2026
+ console.log("Silent token acquisition fails.");
2027
+ if (error instanceof InteractionRequiredAuthError) {
2028
+ return this.acquireToken();
2029
+ }
2030
+ return of(null);
2031
+ }));
2032
+ }
2033
+ }
2034
+ catch (error) {
2035
+ console.error("An error occurred: ", error);
2021
2036
  }
2022
2037
  return of(null);
2023
2038
  }
@@ -2091,7 +2106,13 @@ class AuthService extends ApiServiceBase {
2091
2106
  }
2092
2107
  //MSAL check
2093
2108
  isUserAuthenticated() {
2094
- return this.msalService.instance.getActiveAccount() != null;
2109
+ try {
2110
+ return this.msalService.instance.getActiveAccount() != null;
2111
+ }
2112
+ catch (error) {
2113
+ console.error("An error occurred: ", error);
2114
+ }
2115
+ return false;
2095
2116
  }
2096
2117
  //MSAL + appContext check
2097
2118
  isUserSignedIn() {
@@ -2475,8 +2496,8 @@ class AnatolyHttpInterceptor {
2475
2496
  }
2476
2497
  },
2477
2498
  error: (err) => {
2478
- this.onRequestEnd(loadingRequired);
2479
2499
  this.logger.error(err);
2500
+ this.onRequestEnd(loadingRequired);
2480
2501
  }
2481
2502
  }));
2482
2503
  }
@@ -2550,17 +2571,23 @@ class AnatolyHttpInterceptor {
2550
2571
  req = req.clone({ url: newUrl });
2551
2572
  req = req.clone({ headers: req.headers.set('Accept', 'application/json') });
2552
2573
  req = req.clone({ headers: req.headers.set('Accept', 'application/text') });
2553
- this.onRequestStart(loadingRequired);
2554
- if (authorizationTokenRequired) {
2555
- return this.authService.getAccessToken().pipe(mergeMap((token) => {
2556
- if (token) {
2557
- req = req.clone({ headers: req.headers.set('Authorization', 'Bearer ' + token) });
2558
- }
2574
+ try {
2575
+ this.onRequestStart(loadingRequired);
2576
+ if (authorizationTokenRequired) {
2577
+ return this.authService.getAccessToken().pipe(mergeMap((token) => {
2578
+ if (token) {
2579
+ req = req.clone({ headers: req.headers.set('Authorization', 'Bearer ' + token) });
2580
+ }
2581
+ return this.handleHttpRequest(req, next, loadingRequired);
2582
+ }));
2583
+ }
2584
+ else {
2559
2585
  return this.handleHttpRequest(req, next, loadingRequired);
2560
- }));
2586
+ }
2561
2587
  }
2562
- else {
2563
- return this.handleHttpRequest(req, next, loadingRequired);
2588
+ catch (err) {
2589
+ this.logger.error("An error occurred: " + err);
2590
+ this.onRequestEnd(loadingRequired);
2564
2591
  }
2565
2592
  }
2566
2593
  //Events