Merge pull request #7637 from vvlladd28/bug/catch-error/refresh-token
[3.4.2] UI: Fixes incorrect process error handling when updating JWT
This commit is contained in:
		
						commit
						8a2fe097ef
					
				@ -195,18 +195,22 @@ export class AuthService {
 | 
				
			|||||||
      ));
 | 
					      ));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public logout(captureLastUrl: boolean = false) {
 | 
					  public logout(captureLastUrl: boolean = false, ignoreRequest = false) {
 | 
				
			||||||
    if (captureLastUrl) {
 | 
					    if (captureLastUrl) {
 | 
				
			||||||
      this.redirectUrl = this.router.url;
 | 
					      this.redirectUrl = this.router.url;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.http.post('/api/auth/logout', null, defaultHttpOptions(true, true))
 | 
					    if (!ignoreRequest) {
 | 
				
			||||||
      .subscribe(() => {
 | 
					      this.http.post('/api/auth/logout', null, defaultHttpOptions(true, true))
 | 
				
			||||||
          this.clearJwtToken();
 | 
					        .subscribe(() => {
 | 
				
			||||||
        },
 | 
					            this.clearJwtToken();
 | 
				
			||||||
        () => {
 | 
					          },
 | 
				
			||||||
          this.clearJwtToken();
 | 
					          () => {
 | 
				
			||||||
        }
 | 
					            this.clearJwtToken();
 | 
				
			||||||
      );
 | 
					          }
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      this.clearJwtToken();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private notifyUserLoaded(isUserLoaded: boolean) {
 | 
					  private notifyUserLoaded(isUserLoaded: boolean) {
 | 
				
			||||||
 | 
				
			|||||||
@ -103,7 +103,8 @@ export class GlobalHttpInterceptor implements HttpInterceptor {
 | 
				
			|||||||
    const ignoreErrors = config.ignoreErrors;
 | 
					    const ignoreErrors = config.ignoreErrors;
 | 
				
			||||||
    const resendRequest = config.resendRequest;
 | 
					    const resendRequest = config.resendRequest;
 | 
				
			||||||
    const errorCode = errorResponse.error ? errorResponse.error.errorCode : null;
 | 
					    const errorCode = errorResponse.error ? errorResponse.error.errorCode : null;
 | 
				
			||||||
    if (errorResponse.error && errorResponse.error.refreshTokenPending || errorResponse.status === 401) {
 | 
					    if (errorResponse.error && errorResponse.error.refreshTokenPending ||
 | 
				
			||||||
 | 
					      errorResponse.status === 401 && req.url !== Constants.entryPoints.tokenRefresh) {
 | 
				
			||||||
      if (errorResponse.error && errorResponse.error.refreshTokenPending ||
 | 
					      if (errorResponse.error && errorResponse.error.refreshTokenPending ||
 | 
				
			||||||
          errorCode && errorCode === Constants.serverErrorCode.jwtTokenExpired) {
 | 
					          errorCode && errorCode === Constants.serverErrorCode.jwtTokenExpired) {
 | 
				
			||||||
          return this.refreshTokenAndRetry(req, next);
 | 
					          return this.refreshTokenAndRetry(req, next);
 | 
				
			||||||
@ -153,7 +154,7 @@ export class GlobalHttpInterceptor implements HttpInterceptor {
 | 
				
			|||||||
      return this.jwtIntercept(req, next);
 | 
					      return this.jwtIntercept(req, next);
 | 
				
			||||||
    }),
 | 
					    }),
 | 
				
			||||||
    catchError((err: Error) => {
 | 
					    catchError((err: Error) => {
 | 
				
			||||||
      this.authService.logout(true);
 | 
					      this.authService.logout(true, true);
 | 
				
			||||||
      const message = err ? err.message : 'Unauthorized!';
 | 
					      const message = err ? err.message : 'Unauthorized!';
 | 
				
			||||||
      return this.handleResponseError(req, next, new HttpErrorResponse({error: {message, timeout: 200}, status: 401}));
 | 
					      return this.handleResponseError(req, next, new HttpErrorResponse({error: {message, timeout: 200}, status: 401}));
 | 
				
			||||||
    }));
 | 
					    }));
 | 
				
			||||||
 | 
				
			|||||||
@ -233,7 +233,7 @@ export class TelemetryWebsocketService implements TelemetryService {
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            () => {
 | 
					            () => {
 | 
				
			||||||
              this.isOpening = false;
 | 
					              this.isOpening = false;
 | 
				
			||||||
              this.authService.logout(true);
 | 
					              this.authService.logout(true, true);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          );
 | 
					          );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user