handle errors refactor

This commit is contained in:
Sofia Papacharalampous 2024-05-30 17:18:18 +03:00
parent f156d79ace
commit 9e441079fb
23 changed files with 140 additions and 133 deletions

View File

@ -137,20 +137,15 @@ export class CssColorsEditorComponent extends BasePendingChangesComponent implem
console.log("Error:", errorResponse); console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) { if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error); this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
if(errorResponse.error.code === ResponseErrorCode.TenantConfigurationTypeCanNotChange){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
if(errorResponse.error.code === ResponseErrorCode.MultipleTenantConfigurationTypeNotAllowed){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
} }
} }
onCallbackSuccess(data?: any): void { onCallbackSuccess(data?: any): void {
console.log("Success:", data); console.log("Success:", data);

View File

@ -114,23 +114,17 @@ export class DefaultUserLocaleEditorComponent extends BasePendingChangesComponen
} }
onCallbackError(errorResponse: HttpErrorResponse) { onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse); console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) { if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error); this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
if(errorResponse.error.code === ResponseErrorCode.TenantConfigurationTypeCanNotChange){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
if(errorResponse.error.code === ResponseErrorCode.MultipleTenantConfigurationTypeNotAllowed){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
} }
} }
onCallbackSuccess(data?: any): void { onCallbackSuccess(data?: any): void {
console.log("Success:", data); console.log("Success:", data);

View File

@ -91,23 +91,17 @@ export class DepositEditorComponent extends BasePendingChangesComponent implemen
} }
onCallbackError(errorResponse: HttpErrorResponse) { onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse); console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) { if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error); this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
if(errorResponse.error.code === ResponseErrorCode.TenantConfigurationTypeCanNotChange){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
if(errorResponse.error.code === ResponseErrorCode.MultipleTenantConfigurationTypeNotAllowed){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
} }
} }
onCallbackSuccess(data?: any): void { onCallbackSuccess(data?: any): void {
console.log("Success:", data); console.log("Success:", data);

View File

@ -90,23 +90,17 @@ export class FileTransformerEditorComponent extends BasePendingChangesComponent
} }
onCallbackError(errorResponse: HttpErrorResponse) { onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse); console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) { if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error); this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
if(errorResponse.error.code === ResponseErrorCode.TenantConfigurationTypeCanNotChange){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
if(errorResponse.error.code === ResponseErrorCode.MultipleTenantConfigurationTypeNotAllowed){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
} }
} }
onCallbackSuccess(data?: any): void { onCallbackSuccess(data?: any): void {
console.log("Success:", data); console.log("Success:", data);

View File

@ -101,21 +101,14 @@ export class LogoEditorComponent extends BasePendingChangesComponent implements
} }
onCallbackError(errorResponse: HttpErrorResponse) { onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse); console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) { if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error); this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
if(errorResponse.error.code === ResponseErrorCode.TenantConfigurationTypeCanNotChange){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
if(errorResponse.error.code === ResponseErrorCode.MultipleTenantConfigurationTypeNotAllowed){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
} }
} }
onCallbackSuccess(data?: any): void { onCallbackSuccess(data?: any): void {

View File

@ -110,12 +110,12 @@ export class UserRoleEditorComponent extends BaseComponent implements OnInit, On
} }
onCallbackError(errorResponse: HttpErrorResponse) { onCallbackError(errorResponse: HttpErrorResponse) {
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) { if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error); this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
} }
} }

View File

@ -1,8 +1,10 @@
import { HttpErrorResponse } from "@angular/common/http";
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { UserService } from "@app/core/services/user/user.service"; import { UserService } from "@app/core/services/user/user.service";
import { BaseComponent } from '@common/base/base.component'; import { BaseComponent } from '@common/base/base.component';
import { HttpError, HttpErrorHandlingService } from "@common/modules/errors/error-handling/http-error-handling.service";
import { Guid } from "@common/types/guid"; import { Guid } from "@common/types/guid";
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from "rxjs/operators"; import { takeUntil } from "rxjs/operators";
@ -26,6 +28,7 @@ export class MergeEmailConfirmation extends BaseComponent implements OnInit {
private router: Router, private router: Router,
private language: TranslateService, private language: TranslateService,
private uiNotificationService: UiNotificationService, private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService
) { super(); } ) { super(); }
ngOnInit() { ngOnInit() {
@ -58,12 +61,15 @@ export class MergeEmailConfirmation extends BaseComponent implements OnInit {
}); });
} }
onCallbackError(error: any) { onCallbackError(errorResponse: HttpErrorResponse) {
if (error.status === 302) { const errorOverrides = new Map<number, string>();
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND'), SnackBarNotificationLevel.Warning); errorOverrides.set(302, this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND'));
errorOverrides.set(-1, this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL'));
this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 302) {
this.router.navigate(['home']); this.router.navigate(['home']);
} else {
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL'), SnackBarNotificationLevel.Error);
} }
} }
} }

View File

@ -1,8 +1,10 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { UserService } from '@app/core/services/user/user.service'; import { UserService } from '@app/core/services/user/user.service';
import { BaseComponent } from '@common/base/base.component'; import { BaseComponent } from '@common/base/base.component';
import { HttpError, HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
import { Guid } from '@common/types/guid'; import { Guid } from '@common/types/guid';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from "rxjs/operators"; import { takeUntil } from "rxjs/operators";
@ -25,6 +27,7 @@ export class UnlinkEmailConfirmation extends BaseComponent implements OnInit {
private router: Router, private router: Router,
private language: TranslateService, private language: TranslateService,
private uiNotificationService: UiNotificationService, private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService
) { super(); } ) { super(); }
ngOnInit() { ngOnInit() {
@ -54,13 +57,16 @@ export class UnlinkEmailConfirmation extends BaseComponent implements OnInit {
this.router.navigate(['home']); this.router.navigate(['home']);
} }
onCallbackError(error: any) { onCallbackError(errorResponse: HttpErrorResponse) {
if (error.status === 302) {
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND'), SnackBarNotificationLevel.Warning); let errorOverrides = new Map<number, string>();
errorOverrides.set(302, this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND'));
errorOverrides.set(-1, this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL'));
this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 302) {
this.router.navigate(['home']); this.router.navigate(['home']);
} else {
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL'), SnackBarNotificationLevel.Error);
} }
} }
} }

View File

@ -11,6 +11,7 @@ import { takeUntil } from 'rxjs/operators';
import { FormService } from '@common/forms/form-service'; import { FormService } from '@common/forms/form-service';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { AnalyticsService } from '@app/core/services/matomo/analytics-service'; import { AnalyticsService } from '@app/core/services/matomo/analytics-service';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({ @Component({
selector: 'app-contact-content', selector: 'app-contact-content',
@ -31,7 +32,8 @@ export class ContactContentComponent extends BaseComponent implements OnInit {
private language: TranslateService, private language: TranslateService,
private formService: FormService, private formService: FormService,
private httpClient: HttpClient, private httpClient: HttpClient,
private analyticsService: AnalyticsService private analyticsService: AnalyticsService,
private httpErrorHandlingService: HttpErrorHandlingService
) { ) {
super(); super();
} }
@ -68,7 +70,10 @@ export class ContactContentComponent extends BaseComponent implements OnInit {
onCallbackError(errorResponse: any) { onCallbackError(errorResponse: any) {
this.setErrorModel(errorResponse.error); this.setErrorModel(errorResponse.error);
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-EMAIL-SEND'), SnackBarNotificationLevel.Error);
let errorOverrides = new Map<number, string>();
errorOverrides.set(-1, this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-EMAIL-SEND'));
this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error)
} }
public setErrorModel(validationErrorModel: ValidationErrorModel) { public setErrorModel(validationErrorModel: ValidationErrorModel) {

View File

@ -9,6 +9,8 @@ import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { DmpCloneDialogEditorModel } from './dmp-clone-dialog.editor.model'; import { DmpCloneDialogEditorModel } from './dmp-clone-dialog.editor.model';
import { DmpEditorResolver } from '../dmp-editor-blueprint/dmp-editor.resolver'; import { DmpEditorResolver } from '../dmp-editor-blueprint/dmp-editor.resolver';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
import { HttpErrorResponse } from '@angular/common/http';
@Component({ @Component({
selector: 'app-dmp-clone-dialog', selector: 'app-dmp-clone-dialog',
@ -25,6 +27,7 @@ export class CloneDmpDialogComponent extends BaseComponent {
public dialogRef: MatDialogRef<CloneDmpDialogComponent>, public dialogRef: MatDialogRef<CloneDmpDialogComponent>,
private dmpService: DmpService, private dmpService: DmpService,
private uiNotificationService: UiNotificationService, private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService,
private language: TranslateService, private language: TranslateService,
@Inject(MAT_DIALOG_DATA) public data: any @Inject(MAT_DIALOG_DATA) public data: any
) { ) {
@ -83,7 +86,9 @@ export class CloneDmpDialogComponent extends BaseComponent {
} }
} }
onCallbackError(error: any) { onCallbackError(errorResponse: HttpErrorResponse) {
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Error); let errorOverrides = new Map<number, string>();
errorOverrides.set(-1, errorResponse.error.message ? errorResponse.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-UPDATE'));
this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error);
} }
} }

View File

@ -17,6 +17,8 @@ import { TranslateService } from '@ngx-translate/core';
import { DmpEditorModel } from '../../dmp-editor-blueprint/dmp-editor.model'; import { DmpEditorModel } from '../../dmp-editor-blueprint/dmp-editor.model';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { DmpBlueprint } from '@app/core/model/dmp-blueprint/dmp-blueprint'; import { DmpBlueprint } from '@app/core/model/dmp-blueprint/dmp-blueprint';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
import { HttpErrorResponse } from '@angular/common/http';
@Component({ @Component({
selector: 'app-invitation-dialog-component', selector: 'app-invitation-dialog-component',
@ -39,6 +41,7 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni
private language: TranslateService, private language: TranslateService,
public dialogRef: MatDialogRef<DmpInvitationDialogComponent>, public dialogRef: MatDialogRef<DmpInvitationDialogComponent>,
private uiNotificationService: UiNotificationService, private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService,
private dmpService: DmpService, private dmpService: DmpService,
private userService: UserService, private userService: UserService,
private filterService: FilterService, private filterService: FilterService,
@ -81,7 +84,9 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-USER-INVITATION-DIALOG.SUCCESS'), SnackBarNotificationLevel.Success); this.uiNotificationService.snackBarNotification(this.language.instant('DMP-USER-INVITATION-DIALOG.SUCCESS'), SnackBarNotificationLevel.Success);
} }
onCallbackError(errorResponse: any) { onCallbackError(errorResponse: HttpErrorResponse) {
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-USER-INVITATION-DIALOG.ERROR'), SnackBarNotificationLevel.Error); let errorOverrides = new Map<number, string>();
errorOverrides.set(-1, this.language.instant('DMP-USER-INVITATION-DIALOG.ERROR'));
this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error);
} }
} }

View File

@ -9,7 +9,6 @@ import { ActivatedRoute, Router } from '@angular/router';
import { RecentActivityOrder } from '@app/core/common/enum/recent-activity-order'; import { RecentActivityOrder } from '@app/core/common/enum/recent-activity-order';
import { AuthService } from '@app/core/services/auth/auth.service'; import { AuthService } from '@app/core/services/auth/auth.service';
import { DmpService } from '@app/core/services/dmp/dmp.service'; import { DmpService } from '@app/core/services/dmp/dmp.service';
import { UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { GuidedTour, Orientation } from '@app/library/guided-tour/guided-tour.constants'; import { GuidedTour, Orientation } from '@app/library/guided-tour/guided-tour.constants';
import { GuidedTourService } from '@app/library/guided-tour/guided-tour.service'; import { GuidedTourService } from '@app/library/guided-tour/guided-tour.service';
@ -36,6 +35,7 @@ import { DescriptionStatus } from '@app/core/common/enum/description-status';
import { SortDirection } from '@common/modules/hybrid-listing/hybrid-listing.component'; import { SortDirection } from '@common/modules/hybrid-listing/hybrid-listing.component';
import { AnalyticsService } from '@app/core/services/matomo/analytics-service'; import { AnalyticsService } from '@app/core/services/matomo/analytics-service';
import { DescriptionTemplate } from '@app/core/model/description-template/description-template'; import { DescriptionTemplate } from '@app/core/model/description-template/description-template';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({ @Component({
selector: 'app-dmp-listing-component', selector: 'app-dmp-listing-component',
@ -86,7 +86,7 @@ export class DmpListingComponent extends BaseComponent implements OnInit { //IBr
public dialog: MatDialog, public dialog: MatDialog,
public enumUtils: EnumUtils, public enumUtils: EnumUtils,
private language: TranslateService, private language: TranslateService,
private uiNotificationService: UiNotificationService, private httpErrorHandlingService: HttpErrorHandlingService,
private authService: AuthService, private authService: AuthService,
private guidedTourService: GuidedTourService, private guidedTourService: GuidedTourService,
private httpClient: HttpClient, private httpClient: HttpClient,
@ -266,7 +266,9 @@ export class DmpListingComponent extends BaseComponent implements OnInit { //IBr
if (lookup?.page?.offset === 0) this.listingItems = []; if (lookup?.page?.offset === 0) this.listingItems = [];
this.listingItems.push(...result.items); this.listingItems.push(...result.items);
this.hasListingItems = true; this.hasListingItems = true;
}); },
error => this.httpErrorHandlingService.handleBackedRequestError(error));
}else{ }else{
this.dmpService.query(lookup).pipe(takeUntil(this._destroyed)) this.dmpService.query(lookup).pipe(takeUntil(this._destroyed))
.subscribe(result => { .subscribe(result => {
@ -286,7 +288,8 @@ export class DmpListingComponent extends BaseComponent implements OnInit { //IBr
}) })
// this.listingItems.push(...result.items); // this.listingItems.push(...result.items);
this.hasListingItems = true; this.hasListingItems = true;
}); },
error => this.httpErrorHandlingService.handleBackedRequestError(error));
} }
} }

View File

@ -21,6 +21,8 @@ import { FilterService } from '@common/modules/text-filter/filter-service';
import { Guid } from '@common/types/guid'; import { Guid } from '@common/types/guid';
import { FormService } from '@common/forms/form-service'; import { FormService } from '@common/forms/form-service';
import { MatSelectionListChange } from '@angular/material/list'; import { MatSelectionListChange } from '@angular/material/list';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
import { HttpErrorResponse } from '@angular/common/http';
@Component({ @Component({
selector: 'app-dmp-new-version-dialog', selector: 'app-dmp-new-version-dialog',
@ -73,6 +75,7 @@ export class NewVersionDmpDialogComponent extends BaseComponent {
private dmpService: DmpService, private dmpService: DmpService,
public dmpBlueprintService: DmpBlueprintService, public dmpBlueprintService: DmpBlueprintService,
private uiNotificationService: UiNotificationService, private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService,
private language: TranslateService, private language: TranslateService,
private filterService: FilterService, private filterService: FilterService,
private formService: FormService, private formService: FormService,
@ -204,10 +207,10 @@ export class NewVersionDmpDialogComponent extends BaseComponent {
} }
} }
onCallbackError(error: any) { onCallbackError(errorResponse: HttpErrorResponse) {
this.uiNotificationService.snackBarNotification( let errorOverrides = new Map<number, string>();
error.error.message ? error.error.message : errorOverrides.set(-1, errorResponse.error.message ? errorResponse.error.message : errorResponse.error.error ? errorResponse.error.error : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'));
error.error.error ? error.error.error : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error); this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error);
} }
selectTemplate(event: any): void { selectTemplate(event: any): void {

View File

@ -15,8 +15,9 @@ import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { AuthService } from "@app/core/services/auth/auth.service"; import { AuthService } from "@app/core/services/auth/auth.service";
import { UserGuideDialogComponent } from '@app/ui/user-guide/dialog/user-guide-dialog.component'; import { UserGuideDialogComponent } from '@app/ui/user-guide/dialog/user-guide-dialog.component';
import { HttpClient } from '@angular/common/http'; import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { AnalyticsService } from '@app/core/services/matomo/analytics-service'; import { AnalyticsService } from '@app/core/services/matomo/analytics-service';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({ @Component({
selector: 'app-sidebar-footer', selector: 'app-sidebar-footer',
@ -38,6 +39,7 @@ export class SidebarFooterComponent extends BaseComponent implements OnInit {
private authentication: AuthService, private authentication: AuthService,
private httpClient: HttpClient, private httpClient: HttpClient,
private analyticsService: AnalyticsService, private analyticsService: AnalyticsService,
private httpErrorHandlingService: HttpErrorHandlingService
) { ) {
super(); super();
} }
@ -123,10 +125,13 @@ export class SidebarFooterComponent extends BaseComponent implements OnInit {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-EMAIL-SEND'), SnackBarNotificationLevel.Success); this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-EMAIL-SEND'), SnackBarNotificationLevel.Success);
} }
onCallbackError(errorResponse: any) { onCallbackError(errorResponse: HttpErrorResponse) {
this.setErrorModel(errorResponse.error); this.setErrorModel(errorResponse.error);
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-EMAIL-SEND'), SnackBarNotificationLevel.Error);
let errorOverrides = new Map<number, string>();
errorOverrides.set(-1, this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-EMAIL-SEND'));
this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error);
} }
public setErrorModel(validationErrorModel: ValidationErrorModel) { public setErrorModel(validationErrorModel: ValidationErrorModel) {

View File

@ -37,6 +37,7 @@ import { map, takeUntil } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof'; import { nameof } from 'ts-simple-nameof';
import { AddAccountDialogComponent } from './add-account/add-account-dialog.component'; import { AddAccountDialogComponent } from './add-account/add-account-dialog.component';
import { UserProfileEditorModel } from './user-profile-editor.model'; import { UserProfileEditorModel } from './user-profile-editor.model';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({ @Component({
selector: 'app-user-profile', selector: 'app-user-profile',
@ -86,6 +87,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
private referenceService: ReferenceService, private referenceService: ReferenceService,
private referenceTypeService: ReferenceTypeService, private referenceTypeService: ReferenceTypeService,
private analyticsService: AnalyticsService, private analyticsService: AnalyticsService,
private httpErrorHandlingService: HttpErrorHandlingService
) { ) {
super(); super();
this.languages = this.languageService.getAvailableLanguagesCodes(); this.languages = this.languageService.getAvailableLanguagesCodes();
@ -234,7 +236,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
window.location.reload(); window.location.reload();
}); });
}, },
error => this.onCallbackError(error)); error => this.httpErrorHandlingService.handleBackedRequestError(error));
} }
public unlock() { public unlock() {
@ -279,15 +281,11 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
}, maxWidth: '30em' }, maxWidth: '30em'
}); });
}, },
error => this.onCallbackError(error)); error => this.httpErrorHandlingService.handleBackedRequestError(error));
} }
}); });
} }
onCallbackError(errorResponse: HttpErrorResponse) {
this.uiNotificationService.snackBarNotification(errorResponse.message, SnackBarNotificationLevel.Warning);
}
public addAccount() { public addAccount() {
const dialogRef = this.dialog.open(AddAccountDialogComponent, { const dialogRef = this.dialog.open(AddAccountDialogComponent, {
restoreFocus: false, restoreFocus: false,
@ -311,7 +309,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
}); });
} }
}, },
error => this.onCallbackError(error)); //TODO how to handle this error => this.httpErrorHandlingService.handleBackedRequestError(error)); //TODO how to handle this
} }
}); });
} }

View File

@ -23,7 +23,8 @@
"UNSUCCESSFUL-EMAIL-SEND": "Failed sending email", "UNSUCCESSFUL-EMAIL-SEND": "Failed sending email",
"UNSUCCESSFUL-REMOVE-TEMPLATE": "Failed to remove template, one or more Descriptions of this Plan use this template", "UNSUCCESSFUL-REMOVE-TEMPLATE": "Failed to remove template, one or more Descriptions of this Plan use this template",
"UNSUCCESSFUL-FINALIZE": "Unsuccessful Finalize", "UNSUCCESSFUL-FINALIZE": "Unsuccessful Finalize",
"SUCCESSFUL-RESET": "Successful Reset" "SUCCESSFUL-RESET": "Successful Reset",
"NOT-FOUND": "The page you are looking for doesn't exist."
}, },
"ERRORS": { "ERRORS": {
"HTTP-REQUEST-ERROR": "An Unexpected Error Has Occurred" "HTTP-REQUEST-ERROR": "An Unexpected Error Has Occurred"

View File

@ -126,28 +126,17 @@ export abstract class BaseEditor<EditorModelType extends BaseEditorModel, Entity
console.log("Error:", errorResponse); console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) { if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error); this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
if(errorResponse.error.code === ResponseErrorCode.HashConflict){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error); if(errorResponse.error.code === ResponseErrorCode.DmpDescriptionTemplateCanNotRemove){
}
else if(errorResponse.error.code === ResponseErrorCode.DmpBlueprintHasNoDescriptionTemplates){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
else if(errorResponse.error.code === ResponseErrorCode.DmpDescriptionTemplateCanNotRemove){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
this.refreshOnNavigateToData(null); this.refreshOnNavigateToData(null);
} }
if(errorResponse.error.code === ResponseErrorCode.TenantCodeExists){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
} }
} }

View File

@ -189,8 +189,11 @@ export abstract class BaseListingComponent<ItemModel, LookupModel extends Lookup
} }
protected onCallbackError(errorResponse: HttpErrorResponse) { protected onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
} }
deepValueGetter(obj: any, path: string): any { deepValueGetter(obj: any, path: string): any {

View File

@ -1,5 +1,6 @@
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { ResponseErrorCode } from '@app/core/common/enum/respone-error-code';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -11,12 +12,39 @@ export class HttpErrorHandlingService {
) { ) {
} }
handleBackedRequestError(errorResponse: HttpErrorResponse, messageOvverrides?: Map<number, string>) { handleBackedRequestError(errorResponse: HttpErrorResponse, messageOvverrides?: Map<number, string>, defaultNotificationLevel: SnackBarNotificationLevel = SnackBarNotificationLevel.Warning) {
const error: HttpError = this.getError(errorResponse); const error: HttpError = this.getError(errorResponse);
if (error.statusCode === 404) { let errorMessage = messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : 'NOT-FOUND';
this.uiNotificationService.snackBarNotification(messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : 'NOT-FOUND', SnackBarNotificationLevel.Warning);
} else { if (error.statusCode === 400) {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning); if(errorResponse.error.code === ResponseErrorCode.HashConflict){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
else if(errorResponse.error.code === ResponseErrorCode.DmpBlueprintHasNoDescriptionTemplates){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
else if(errorResponse.error.code === ResponseErrorCode.DmpDescriptionTemplateCanNotRemove){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
else if(errorResponse.error.code === ResponseErrorCode.TenantCodeExists){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
else if(errorResponse.error.code === ResponseErrorCode.TenantConfigurationTypeCanNotChange){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
else if(errorResponse.error.code === ResponseErrorCode.MultipleTenantConfigurationTypeNotAllowed){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
}
if (error.statusCode === 302 || error.statusCode === 404) {
this.uiNotificationService.snackBarNotification(errorMessage, SnackBarNotificationLevel.Warning);
}
else {
let errorMessage = messageOvverrides?.has(-1) ? messageOvverrides?.get(error.statusCode) : error.getMessagesString();
this.uiNotificationService.snackBarNotification(errorMessage, defaultNotificationLevel);
} }
} }

View File

@ -139,23 +139,17 @@ export class NotifierListEditorComponent extends BasePendingChangesComponent imp
moveItemInArray(this.availableNotifiers[type], event.previousIndex, event.currentIndex); moveItemInArray(this.availableNotifiers[type], event.previousIndex, event.currentIndex);
} }
onCallbackError(errorResponse: HttpErrorResponse) { onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse); console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) { if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error); this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
if(errorResponse.error.code === ResponseErrorCode.TenantConfigurationTypeCanNotChange){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
if(errorResponse.error.code === ResponseErrorCode.MultipleTenantConfigurationTypeNotAllowed){
this.uiNotificationService.snackBarNotification(errorResponse.error.error, SnackBarNotificationLevel.Error);
}
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
} }
} }
onCallbackSuccess(data?: any): void { onCallbackSuccess(data?: any): void {
console.log("Success:", data); console.log("Success:", data);

View File

@ -74,7 +74,7 @@ export class InAppNotificationEditorComponent extends BaseComponent implements O
if(!this.isDeleted && !this.isRead) this.markAsRead() if(!this.isDeleted && !this.isRead) this.markAsRead()
}, },
error => this.onCallbackError(error) error => this.httpErrorHandlingService.handleBackedRequestError(error)
); );
} else { } else {
this.inappNotification = null; this.inappNotification = null;
@ -87,7 +87,7 @@ export class InAppNotificationEditorComponent extends BaseComponent implements O
this.inappNotificationService.read(value.id).pipe(takeUntil(this._destroyed)) this.inappNotificationService.read(value.id).pipe(takeUntil(this._destroyed))
.subscribe( .subscribe(
complete => this.onCallbackSuccess(), complete => this.onCallbackSuccess(),
error => this.onCallbackError(error) error => this.httpErrorHandlingService.handleBackedRequestError(error)
); );
// this.clearErrorModel(); // this.clearErrorModel();
} }
@ -109,7 +109,7 @@ export class InAppNotificationEditorComponent extends BaseComponent implements O
this.inappNotificationService.delete(value.id).pipe(takeUntil(this._destroyed)) this.inappNotificationService.delete(value.id).pipe(takeUntil(this._destroyed))
.subscribe( .subscribe(
complete => this.cancel(), complete => this.cancel(),
error => this.onCallbackError(error) error => this.httpErrorHandlingService.handleBackedRequestError(error)
); );
} }
}); });
@ -124,9 +124,4 @@ export class InAppNotificationEditorComponent extends BaseComponent implements O
// this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success); // this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
// this.router.navigate(['/mine-notifications']); // this.router.navigate(['/mine-notifications']);
} }
onCallbackError(errorResponse: HttpErrorResponse) {
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
} }

View File

@ -57,11 +57,6 @@ export class MineInAppNotificationListingDialogComponent extends BaseComponent i
this.resizeSubscription.unsubscribe(); this.resizeSubscription.unsubscribe();
} }
private onCallbackError(errorResponse: HttpErrorResponse) {
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
goToNotification(item: InAppNotification) { goToNotification(item: InAppNotification) {
if (item.trackingState === NotificationInAppTracking.Stored) { if (item.trackingState === NotificationInAppTracking.Stored) {
this.inappNotificationService.read(item.id) this.inappNotificationService.read(item.id)
@ -124,7 +119,7 @@ export class MineInAppNotificationListingDialogComponent extends BaseComponent i
data => { data => {
this.inappNotifications = data.items; this.inappNotifications = data.items;
}, },
error => this.onCallbackError(error), error => this.httpErrorHandlingService.handleBackedRequestError(error)
); );
} }
} }

View File

@ -125,11 +125,7 @@ export class UserProfileNotifierListEditorComponent extends BaseComponent implem
onCallbackError(errorResponse: HttpErrorResponse) { onCallbackError(errorResponse: HttpErrorResponse) {
this.notificationTrackingProcess = NotificationTrackingProcess.ERROR; this.notificationTrackingProcess = NotificationTrackingProcess.ERROR;
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
if (error.statusCode === 400) {
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
} }
dropped(event: CdkDragDrop<string[]>, type: NotificationType) { dropped(event: CdkDragDrop<string[]>, type: NotificationType) {