From: Tiago Melo Date: Fri, 4 May 2018 14:16:51 +0000 (+0100) Subject: mgr/dashboard: Add error handling on the frontend X-Git-Tag: v14.0.0~181^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cf4adb4da383917a0388bf220158f2d574b6aa07;p=ceph.git mgr/dashboard: Add error handling on the frontend Now all error notifications are processed on the api-interceptor-service, removing the need to handle them on every api request. Signed-off-by: Tiago Melo --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-form/rbd-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-form/rbd-form.component.ts index 5228063ddc30..74919ee9f08f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-form/rbd-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-form/rbd-form.component.ts @@ -462,9 +462,6 @@ export class RbdFormComponent implements OnInit { this.router.navigate(['/block/rbd']); }, (resp) => { this.rbdForm.setErrors({'cdSubmitButton': true}); - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } @@ -521,9 +518,6 @@ export class RbdFormComponent implements OnInit { this.router.navigate(['/block/rbd']); }).catch((resp) => { this.rbdForm.setErrors({'cdSubmitButton': true}); - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } @@ -556,9 +550,6 @@ export class RbdFormComponent implements OnInit { this.router.navigate(['/block/rbd']); }, (resp) => { this.rbdForm.setErrors({'cdSubmitButton': true}); - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } @@ -608,9 +599,6 @@ export class RbdFormComponent implements OnInit { this.router.navigate(['/block/rbd']); }).catch((resp) => { this.rbdForm.setErrors({'cdSubmitButton': true}); - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts index 41a0c03e59f7..fb8a6e4f59ea 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts @@ -258,9 +258,6 @@ export class RbdListComponent implements OnInit, OnDestroy { this.loadImages(null); }).catch((resp) => { this.modalRef.content.stopLoadingSpinner(); - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } @@ -300,10 +297,6 @@ export class RbdListComponent implements OnInit, OnDestroy { } this.modalRef.hide(); this.loadImages(null); - }).catch((resp) => { - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-form/rbd-snapshot-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-form/rbd-snapshot-form.component.ts index 42d19b320fa4..e18e5bca110c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-form/rbd-snapshot-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-form/rbd-snapshot-form.component.ts @@ -74,9 +74,6 @@ export class RbdSnapshotFormComponent implements OnInit { this.onSubmit.next(this.snapName); }).catch((resp) => { this.snapshotForm.setErrors({'cdSubmitButton': true}); - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } @@ -99,9 +96,6 @@ export class RbdSnapshotFormComponent implements OnInit { this.onSubmit.next(snapshotName); }).catch((resp) => { this.snapshotForm.setErrors({'cdSubmitButton': true}); - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.ts index 4b5abeb17a48..23b6a1298989 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.ts @@ -178,10 +178,6 @@ export class RbdSnapshotListComponent implements OnInit, OnChanges { (asyncFinishedTask: FinishedTask) => { this.notificationService.notifyTask(asyncFinishedTask); }); - }).catch((resp) => { - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } @@ -208,9 +204,6 @@ export class RbdSnapshotListComponent implements OnInit, OnChanges { }) .catch((resp) => { this.modalRef.content.stopLoadingSpinner(); - finishedTask.success = false; - finishedTask.exception = resp.error; - this.notificationService.notifyTask(finishedTask); }); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/enum/components.enum.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/enum/components.enum.ts new file mode 100644 index 000000000000..f5fc998f341f --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/enum/components.enum.ts @@ -0,0 +1,6 @@ +export enum Components { + cephfs = 'CephFS', + rbd = 'RBD', + pool = 'Pool', + osd = 'OSD' +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/task-exception.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/task-exception.ts index 088cbbc19301..ba38e4aab041 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/task-exception.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/task-exception.ts @@ -1,6 +1,9 @@ +import { Task } from './task'; + export class TaskException { status: number; - errno: number; + code: number; component: string; detail: string; + task: Task; } 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 index e2a2cee2a670..40fae89b00ae 100644 --- 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 @@ -8,11 +8,13 @@ import { import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; +import * as _ from 'lodash'; import 'rxjs/add/observable/throw'; import 'rxjs/add/operator/catch'; import { Observable } from 'rxjs/Observable'; import { NotificationType } from '../enum/notification-type.enum'; +import { FinishedTask } from '../models/finished-task'; import { AuthStorageService } from './auth-storage.service'; import { NotificationService } from './notification.service'; @@ -28,6 +30,24 @@ export class ApiInterceptorService implements HttpInterceptor { if (resp instanceof HttpErrorResponse) { let showNotification = true; switch (resp.status) { + case 400: + const finishedTask = new FinishedTask(); + + const task = resp.error.task; + if (_.isPlainObject(task)) { + task.metadata.component = task.metadata.component || resp.error.component; + + finishedTask.name = task.name; + finishedTask.metadata = task.metadata; + } else { + finishedTask.metadata = resp.error; + } + + finishedTask.success = false; + finishedTask.exception = resp.error; + this.notificationService.notifyTask(finishedTask); + showNotification = false; + break; case 401: this.authStorageService.remove(); this.router.navigate(['/login']); @@ -35,9 +55,6 @@ export class ApiInterceptorService implements HttpInterceptor { case 404: this.router.navigate(['/404']); break; - case 409: - showNotification = false; - break; } let timeoutId; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.ts index ab17f01d5596..d563b995d23b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.ts @@ -1,4 +1,6 @@ import { Injectable } from '@angular/core'; + +import { Components } from '../enum/components.enum'; import { FinishedTask } from '../models/finished-task'; import { Task } from '../models/task'; @@ -130,11 +132,13 @@ export class TaskManagerMessageService { return { }; } - ), + ) }; defaultMessage = new TaskManagerMessage( - (metadata) => 'Unknown Task', + (metadata) => { + return Components[metadata.component] || metadata.component || 'Unknown Task'; + }, (metadata) => 'Task executed successfully', () => { return { @@ -151,7 +155,7 @@ export class TaskManagerMessageService { getErrorMessage(finishedTask: FinishedTask) { const taskManagerMessage = this.messages[finishedTask.name] || this.defaultMessage; - return taskManagerMessage.error(finishedTask.metadata)[finishedTask.exception.errno] || + return taskManagerMessage.error(finishedTask.metadata)[finishedTask.exception.code] || finishedTask.exception.detail; }