From c400ad551ecbbf0d9de78031297336b13f46c529 Mon Sep 17 00:00:00 2001 From: Sylvain MATHIEU Date: Fri, 4 Feb 2022 13:38:52 +0100 Subject: [PATCH] bug fix, display correctly http error message inside Toaster service --- .../add-permission-line.component.ts | 7 +++++-- .../role-detail/role-detail.component.ts | 10 ++++++---- .../role-permissions/role-permissions.component.ts | 6 ++++-- .../role-management/role-management.component.ts | 4 +++- .../user-permissions/user-permissions.component.ts | 6 ++++-- src/styles.scss | 1 + 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.ts b/src/app/components/permissions-management/add-permission-line/add-permission-line.component.ts index 27c1b12d..77e48c6d 100644 --- a/src/app/components/permissions-management/add-permission-line/add-permission-line.component.ts +++ b/src/app/components/permissions-management/add-permission-line/add-permission-line.component.ts @@ -16,6 +16,7 @@ import {ApiInformationService} from "@services/api-information.service"; import {Methods, Permission, PermissionActions} from "@models/api/permission"; import {PermissionsService} from "@services/permissions.service"; import {ToasterService} from "@services/toaster.service"; +import {HttpErrorResponse} from "@angular/common/http"; @Component({ selector: 'app-add-permission-line', @@ -72,8 +73,10 @@ export class AddPermissionLineComponent implements OnInit { .subscribe(() => { this.toasterService.success(`permission was created`); this.reset(); - }, (error) => { - this.toasterService.error(error); + }, (error: HttpErrorResponse) => { + this.toasterService.error(` + ${error.message} + ${error.error.message}`); }); } } diff --git a/src/app/components/role-management/role-detail/role-detail.component.ts b/src/app/components/role-management/role-detail/role-detail.component.ts index 3638e78b..0ccb142a 100644 --- a/src/app/components/role-management/role-detail/role-detail.component.ts +++ b/src/app/components/role-management/role-detail/role-detail.component.ts @@ -18,6 +18,7 @@ import {ServerService} from "@services/server.service"; import {Role} from "@models/api/role"; import {FormControl, FormGroup} from "@angular/forms"; import {ToasterService} from "@services/toaster.service"; +import {HttpErrorResponse} from "@angular/common/http"; @Component({ selector: 'app-role-detail', @@ -50,10 +51,11 @@ export class RoleDetailComponent implements OnInit { onUpdate() { this.roleService.update(this.server, this.role) .subscribe(() => { - this.toastService.success(`role: ${this.role.name} was updated`); - }, - (error) => { - this.toastService.error(error); + this.toastService.success(`role: ${this.role.name} was updated`); + }, + (error: HttpErrorResponse) => { + this.toastService.error(`${error.message} + ${error.error.message}`); }); } } diff --git a/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.ts b/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.ts index 2d1f966b..76c8ee5d 100644 --- a/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.ts +++ b/src/app/components/role-management/role-detail/role-permissions/role-permissions.component.ts @@ -20,6 +20,7 @@ import {Role} from "@models/api/role"; import {Permission} from "@models/api/permission"; import {Observable} from "rxjs/Rx"; import {forkJoin} from "rxjs"; +import {HttpErrorResponse} from "@angular/common/http"; @Component({ selector: 'app-role-permissions', @@ -61,8 +62,9 @@ export class RolePermissionsComponent implements OnInit { this.toastService.success(`permissions updated`); this.router.navigate(['/server', this.server.id, 'management', 'roles', this.role.role_id]); }, - (error) => { - this.toastService.error(error); + (error: HttpErrorResponse) => { + this.toastService.error(`${error.message} + ${error.error.message}`); }); } } diff --git a/src/app/components/role-management/role-management.component.ts b/src/app/components/role-management/role-management.component.ts index 1f6e08ad..b0f7b6e6 100644 --- a/src/app/components/role-management/role-management.component.ts +++ b/src/app/components/role-management/role-management.component.ts @@ -26,6 +26,7 @@ import {RoleService} from "@services/role.service"; import {AddRoleDialogComponent} from "@components/role-management/add-role-dialog/add-role-dialog.component"; import {DeleteRoleDialogComponent} from "@components/role-management/delete-role-dialog/delete-role-dialog.component"; import {forkJoin} from "rxjs"; +import {HttpErrorResponse} from "@angular/common/http"; @Component({ @@ -95,7 +96,8 @@ export class RoleManagementComponent implements OnInit { this.toasterService.success(`${role.name} role created`); this.refresh(); }, - (error) => this.toasterService.error(error)); + (error: HttpErrorResponse) => this.toasterService.error(`${error.message} + ${error.error.message}`)); } }); } diff --git a/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.ts b/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.ts index f717bd6a..fd96958f 100644 --- a/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.ts +++ b/src/app/components/user-management/user-detail/user-permissions/user-permissions.component.ts @@ -10,6 +10,7 @@ import {forkJoin} from "rxjs"; import {Observable} from "rxjs/Rx"; import {UserService} from "@services/user.service"; import {User} from "@models/users/user"; +import {HttpErrorResponse} from "@angular/common/http"; @Component({ selector: 'app-user-permissions', @@ -54,8 +55,9 @@ export class UserPermissionsComponent implements OnInit { this.toastService.success(`permissions updated`); this.router.navigate(['/server', this.server.id, 'management', 'users', this.user.user_id]); }, - (error) => { - this.toastService.error(error); + (error: HttpErrorResponse) => { + this.toastService.error(`${error.message} + ${error.error.message}`); }); } diff --git a/src/styles.scss b/src/styles.scss index 0c98b1e6..4c4cc5b1 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -23,6 +23,7 @@ a.table-link { .snackbar-error { background: #b00020 !important; color: white !important; + white-space: pre-wrap !important; } .mat-dialog-actions {