]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Rename auth-interceptor and refactor it to display notifications for...
authorVolker Theile <vtheile@suse.com>
Thu, 12 Apr 2018 16:49:28 +0000 (18:49 +0200)
committerVolker Theile <vtheile@suse.com>
Thu, 19 Apr 2018 14:39:29 +0000 (16:39 +0200)
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/app.module.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-interceptor.service.ts [deleted file]

index d9d6b5f2d84de16e2c796f1d23ad66936413a4a0..4c5974ec304f2cb80b106a0685ab10f8d6e25728 100644 (file)
@@ -10,7 +10,7 @@ import { AppRoutingModule } from './app-routing.module';
 import { AppComponent } from './app.component';
 import { CephModule } from './ceph/ceph.module';
 import { CoreModule } from './core/core.module';
-import { AuthInterceptorService } from './shared/services/auth-interceptor.service';
+import { ApiInterceptorService } from './shared/services/api-interceptor.service';
 import { SharedModule } from './shared/shared.module';
 
 export class CustomOption extends ToastOptions {
@@ -41,7 +41,7 @@ export class CustomOption extends ToastOptions {
   providers: [
     {
       provide: HTTP_INTERCEPTORS,
-      useClass: AuthInterceptorService,
+      useClass: ApiInterceptorService,
       multi: true
     },
     {
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts
new file mode 100644 (file)
index 0000000..d412119
--- /dev/null
@@ -0,0 +1,47 @@
+import {
+  HttpErrorResponse,
+  HttpEvent,
+  HttpHandler,
+  HttpInterceptor,
+  HttpRequest
+} from '@angular/common/http';
+import { Injectable } from '@angular/core';
+import { Router } from '@angular/router';
+
+import 'rxjs/add/observable/throw';
+import 'rxjs/add/operator/catch';
+import { Observable } from 'rxjs/Observable';
+
+import { NotificationType } from '../enum/notification-type.enum';
+import { AuthStorageService } from './auth-storage.service';
+import { NotificationService } from './notification.service';
+
+@Injectable()
+export class ApiInterceptorService implements HttpInterceptor {
+
+  constructor(private router: Router,
+              private authStorageService: AuthStorageService,
+              public notificationService: NotificationService) {}
+
+  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
+    return next.handle(request).catch(resp => {
+      if (resp instanceof HttpErrorResponse) {
+        switch (resp.status) {
+          case 401:
+            this.authStorageService.remove();
+            this.router.navigate(['/login']);
+            break;
+          case 404:
+            this.router.navigate(['/404']);
+            break;
+        }
+        this.notificationService.show(
+          NotificationType.error,
+          resp.error.detail || '',
+          `${resp.status} - ${resp.statusText}`);
+      }
+      // Return the error to the method that called it.
+      return Observable.throw(resp);
+    });
+  }
+}
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-interceptor.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-interceptor.service.ts
deleted file mode 100644 (file)
index 69a6d57..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-import {
-  HttpErrorResponse,
-  HttpEvent,
-  HttpHandler,
-  HttpInterceptor,
-  HttpRequest
-} from '@angular/common/http';
-import { Injectable } from '@angular/core';
-import { Router } from '@angular/router';
-
-import 'rxjs/add/observable/throw';
-import 'rxjs/add/operator/catch';
-import { Observable } from 'rxjs/Observable';
-
-import { NotificationType } from '../enum/notification-type.enum';
-import { AuthStorageService } from './auth-storage.service';
-import { NotificationService } from './notification.service';
-
-@Injectable()
-export class AuthInterceptorService implements HttpInterceptor {
-  constructor(
-    private router: Router,
-    private authStorageService: AuthStorageService,
-    public notificationService: NotificationService
-  ) {}
-
-  _notify (resp) {
-    this.notificationService.show(
-      NotificationType.error,
-      resp.error.detail || '',
-      `${resp.status} - ${resp.statusText}`
-    );
-  }
-
-  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
-    return next.handle(request).catch(resp => {
-      if (resp instanceof HttpErrorResponse) {
-        switch (resp.status) {
-          case 404:
-            this.router.navigate(['/404']);
-            break;
-          case 401:
-            this.authStorageService.remove();
-            this.router.navigate(['/login']);
-            this._notify(resp);
-            break;
-          case 500:
-            this._notify(resp);
-            break;
-        }
-      }
-      // Return the error to the method that called it.
-      return Observable.throw(resp);
-    });
-  }
-}