From 8d775bedce26f77e8bf41f6d18edadc20900c207 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Thu, 12 Apr 2018 18:49:28 +0200 Subject: [PATCH] mgr/dashboard: Rename auth-interceptor and refactor it to display notifications for more errors than 401 and 500. Signed-off-by: Volker Theile --- .../dashboard/frontend/src/app/app.module.ts | 4 +-- ....service.ts => api-interceptor.service.ts} | 29 +++++++------------ 2 files changed, 12 insertions(+), 21 deletions(-) rename src/pybind/mgr/dashboard/frontend/src/app/shared/services/{auth-interceptor.service.ts => api-interceptor.service.ts} (68%) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/app.module.ts b/src/pybind/mgr/dashboard/frontend/src/app/app.module.ts index d9d6b5f2d84de..4c5974ec304f2 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/app.module.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/app.module.ts @@ -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/auth-interceptor.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts similarity index 68% rename from src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-interceptor.service.ts rename to src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts index 69a6d57343258..d412119bbc289 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-interceptor.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts @@ -17,37 +17,28 @@ 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 - ) {} +export class ApiInterceptorService implements HttpInterceptor { - _notify (resp) { - this.notificationService.show( - NotificationType.error, - resp.error.detail || '', - `${resp.status} - ${resp.statusText}` - ); - } + constructor(private router: Router, + private authStorageService: AuthStorageService, + public notificationService: NotificationService) {} intercept(request: HttpRequest, next: HttpHandler): Observable> { 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); + 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); -- 2.39.5