Bug 1414 - Is not possible to remove all role-mappings of a user
[osm/NG-UI.git] / src / services / AuthInterceptorService.ts
index ede10a8..8c5a9d7 100644 (file)
@@ -93,8 +93,12 @@ export class AuthInterceptorService implements HttpInterceptor {
             });
         } else {
             this.clonedReq = req.clone({
-                setHeaders: { Authorization: 'Bearer ' + idToken, 'Content-Type': 'charset=UTF-8',
-                'Cache-Control': 'no-cache', Pragma: 'no-cache' }
+                setHeaders: {
+                    Authorization: 'Bearer ' + idToken,
+                    'Content-Type': 'charset=UTF-8',
+                    'Cache-Control': 'no-cache',
+                    Pragma: 'no-cache'
+                }
             });
         }
     }
@@ -103,18 +107,23 @@ export class AuthInterceptorService implements HttpInterceptor {
     public errorRes(err: HttpErrorResponse, req: HttpRequest<{}>, next: HttpHandler): Observable<{}> {
         if (err instanceof HttpErrorResponse) {
             switch (err.status) {
-                case HttpStatus.UNAUTHORIZED || HttpStatus.FORBIDDEN:
+                case HttpStatus.UNAUTHORIZED:
+                case HttpStatus.FORBIDDEN:
                     this.handleError(err);
                     break;
+                case HttpStatus.GATEWAY_TIMEOUT:
+                case HttpStatus.BAD_GATEWAY:
+                    this.notifierService.hideAll();
+                    this.authService.logoutResponse();
+                    break;
                 default: return throwError(err);
             }
         } else { return throwError(err); }
     }
 
-    /** Method to handle  401 & 403 error */
+    /** Method to handle  401, 403 & 502 error */
     private handleError(err: HttpErrorResponse): void {
-        if (err.error.detail === 'Expired Token or Authorization HTTP header' ||
-            err.error.detail === 'Invalid Token or Authorization HTTP header') {
+        if (err.error.detail !== 'Access denied: lack of permissions.' && err.error.detail !== 'You cannot remove system_admin role from admin user') {
             this.notifierService.hideAll();
             this.authService.logoutResponse();
             if (this.authService.handle401) {