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);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) {
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);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
}
onCallbackSuccess(data?: any): void {
console.log("Success:", data);

View File

@ -114,23 +114,17 @@ export class DefaultUserLocaleEditorComponent extends BasePendingChangesComponen
}
onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) {
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);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
}
onCallbackSuccess(data?: any): void {
console.log("Success:", data);

View File

@ -91,23 +91,17 @@ export class DepositEditorComponent extends BasePendingChangesComponent implemen
}
onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) {
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);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
}
onCallbackSuccess(data?: any): void {
console.log("Success:", data);

View File

@ -90,23 +90,17 @@ export class FileTransformerEditorComponent extends BasePendingChangesComponent
}
onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) {
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);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
}
onCallbackSuccess(data?: any): void {
console.log("Success:", data);

View File

@ -101,21 +101,14 @@ export class LogoEditorComponent extends BasePendingChangesComponent implements
}
onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) {
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);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
}
onCallbackSuccess(data?: any): void {

View File

@ -110,12 +110,12 @@ export class UserRoleEditorComponent extends BaseComponent implements OnInit, On
}
onCallbackError(errorResponse: HttpErrorResponse) {
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
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 { ActivatedRoute, Router } from "@angular/router";
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { UserService } from "@app/core/services/user/user.service";
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 { TranslateService } from '@ngx-translate/core';
import { takeUntil } from "rxjs/operators";
@ -26,6 +28,7 @@ export class MergeEmailConfirmation extends BaseComponent implements OnInit {
private router: Router,
private language: TranslateService,
private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService
) { super(); }
ngOnInit() {
@ -58,12 +61,15 @@ export class MergeEmailConfirmation extends BaseComponent implements OnInit {
});
}
onCallbackError(error: any) {
if (error.status === 302) {
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND'), SnackBarNotificationLevel.Warning);
onCallbackError(errorResponse: HttpErrorResponse) {
const 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, SnackBarNotificationLevel.Error)
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 302) {
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 { ActivatedRoute, Router } from '@angular/router';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { UserService } from '@app/core/services/user/user.service';
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 { TranslateService } from '@ngx-translate/core';
import { takeUntil } from "rxjs/operators";
@ -25,6 +27,7 @@ export class UnlinkEmailConfirmation extends BaseComponent implements OnInit {
private router: Router,
private language: TranslateService,
private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService
) { super(); }
ngOnInit() {
@ -54,13 +57,16 @@ export class UnlinkEmailConfirmation extends BaseComponent implements OnInit {
this.router.navigate(['home']);
}
onCallbackError(error: any) {
if (error.status === 302) {
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND'), SnackBarNotificationLevel.Warning);
onCallbackError(errorResponse: HttpErrorResponse) {
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']);
} 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 { HttpClient } from '@angular/common/http';
import { AnalyticsService } from '@app/core/services/matomo/analytics-service';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({
selector: 'app-contact-content',
@ -31,7 +32,8 @@ export class ContactContentComponent extends BaseComponent implements OnInit {
private language: TranslateService,
private formService: FormService,
private httpClient: HttpClient,
private analyticsService: AnalyticsService
private analyticsService: AnalyticsService,
private httpErrorHandlingService: HttpErrorHandlingService
) {
super();
}
@ -68,7 +70,10 @@ export class ContactContentComponent extends BaseComponent implements OnInit {
onCallbackError(errorResponse: any) {
this.setErrorModel(errorResponse.error);
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) {

View File

@ -9,6 +9,8 @@ import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from 'rxjs/operators';
import { DmpCloneDialogEditorModel } from './dmp-clone-dialog.editor.model';
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({
selector: 'app-dmp-clone-dialog',
@ -25,6 +27,7 @@ export class CloneDmpDialogComponent extends BaseComponent {
public dialogRef: MatDialogRef<CloneDmpDialogComponent>,
private dmpService: DmpService,
private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService,
private language: TranslateService,
@Inject(MAT_DIALOG_DATA) public data: any
) {
@ -83,7 +86,9 @@ export class CloneDmpDialogComponent extends BaseComponent {
}
}
onCallbackError(error: any) {
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Error);
onCallbackError(errorResponse: HttpErrorResponse) {
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 { takeUntil } from 'rxjs/operators';
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({
selector: 'app-invitation-dialog-component',
@ -39,6 +41,7 @@ export class DmpInvitationDialogComponent extends BaseComponent implements OnIni
private language: TranslateService,
public dialogRef: MatDialogRef<DmpInvitationDialogComponent>,
private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService,
private dmpService: DmpService,
private userService: UserService,
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);
}
onCallbackError(errorResponse: any) {
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-USER-INVITATION-DIALOG.ERROR'), SnackBarNotificationLevel.Error);
onCallbackError(errorResponse: HttpErrorResponse) {
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 { AuthService } from '@app/core/services/auth/auth.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 { GuidedTour, Orientation } from '@app/library/guided-tour/guided-tour.constants';
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 { AnalyticsService } from '@app/core/services/matomo/analytics-service';
import { DescriptionTemplate } from '@app/core/model/description-template/description-template';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({
selector: 'app-dmp-listing-component',
@ -86,7 +86,7 @@ export class DmpListingComponent extends BaseComponent implements OnInit { //IBr
public dialog: MatDialog,
public enumUtils: EnumUtils,
private language: TranslateService,
private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService,
private authService: AuthService,
private guidedTourService: GuidedTourService,
private httpClient: HttpClient,
@ -266,7 +266,9 @@ export class DmpListingComponent extends BaseComponent implements OnInit { //IBr
if (lookup?.page?.offset === 0) this.listingItems = [];
this.listingItems.push(...result.items);
this.hasListingItems = true;
});
},
error => this.httpErrorHandlingService.handleBackedRequestError(error));
}else{
this.dmpService.query(lookup).pipe(takeUntil(this._destroyed))
.subscribe(result => {
@ -286,7 +288,8 @@ export class DmpListingComponent extends BaseComponent implements OnInit { //IBr
})
// this.listingItems.push(...result.items);
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 { FormService } from '@common/forms/form-service';
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({
selector: 'app-dmp-new-version-dialog',
@ -73,6 +75,7 @@ export class NewVersionDmpDialogComponent extends BaseComponent {
private dmpService: DmpService,
public dmpBlueprintService: DmpBlueprintService,
private uiNotificationService: UiNotificationService,
private httpErrorHandlingService: HttpErrorHandlingService,
private language: TranslateService,
private filterService: FilterService,
private formService: FormService,
@ -204,10 +207,10 @@ export class NewVersionDmpDialogComponent extends BaseComponent {
}
}
onCallbackError(error: any) {
this.uiNotificationService.snackBarNotification(
error.error.message ? error.error.message :
error.error.error ? error.error.error : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
onCallbackError(errorResponse: HttpErrorResponse) {
let errorOverrides = new Map<number, string>();
errorOverrides.set(-1, errorResponse.error.message ? errorResponse.error.message : errorResponse.error.error ? errorResponse.error.error : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'));
this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error);
}
selectTemplate(event: any): void {

View File

@ -15,8 +15,9 @@ import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from 'rxjs/operators';
import { AuthService } from "@app/core/services/auth/auth.service";
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 { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({
selector: 'app-sidebar-footer',
@ -38,6 +39,7 @@ export class SidebarFooterComponent extends BaseComponent implements OnInit {
private authentication: AuthService,
private httpClient: HttpClient,
private analyticsService: AnalyticsService,
private httpErrorHandlingService: HttpErrorHandlingService
) {
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);
}
onCallbackError(errorResponse: any) {
onCallbackError(errorResponse: HttpErrorResponse) {
this.setErrorModel(errorResponse.error);
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) {

View File

@ -37,6 +37,7 @@ import { map, takeUntil } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
import { AddAccountDialogComponent } from './add-account/add-account-dialog.component';
import { UserProfileEditorModel } from './user-profile-editor.model';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({
selector: 'app-user-profile',
@ -86,6 +87,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
private referenceService: ReferenceService,
private referenceTypeService: ReferenceTypeService,
private analyticsService: AnalyticsService,
private httpErrorHandlingService: HttpErrorHandlingService
) {
super();
this.languages = this.languageService.getAvailableLanguagesCodes();
@ -234,7 +236,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
window.location.reload();
});
},
error => this.onCallbackError(error));
error => this.httpErrorHandlingService.handleBackedRequestError(error));
}
public unlock() {
@ -279,15 +281,11 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
}, maxWidth: '30em'
});
},
error => this.onCallbackError(error));
error => this.httpErrorHandlingService.handleBackedRequestError(error));
}
});
}
onCallbackError(errorResponse: HttpErrorResponse) {
this.uiNotificationService.snackBarNotification(errorResponse.message, SnackBarNotificationLevel.Warning);
}
public addAccount() {
const dialogRef = this.dialog.open(AddAccountDialogComponent, {
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-REMOVE-TEMPLATE": "Failed to remove template, one or more Descriptions of this Plan use this template",
"UNSUCCESSFUL-FINALIZE": "Unsuccessful Finalize",
"SUCCESSFUL-RESET": "Successful Reset"
"SUCCESSFUL-RESET": "Successful Reset",
"NOT-FOUND": "The page you are looking for doesn't exist."
},
"ERRORS": {
"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);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) {
this.editorModel.validationErrorModel.fromJSONObject(errorResponse.error);
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);
if(errorResponse.error.code === ResponseErrorCode.DmpDescriptionTemplateCanNotRemove){
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);
} 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) {
console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
deepValueGetter(obj: any, path: string): any {

View File

@ -1,5 +1,6 @@
import { HttpErrorResponse } from '@angular/common/http';
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 { 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);
if (error.statusCode === 404) {
this.uiNotificationService.snackBarNotification(messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : 'NOT-FOUND', SnackBarNotificationLevel.Warning);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
let errorMessage = messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : 'NOT-FOUND';
if (error.statusCode === 400) {
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);
}
onCallbackError(errorResponse: HttpErrorResponse) {
console.log("Error:", errorResponse);
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) {
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);
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
}
onCallbackSuccess(data?: any): void {
console.log("Success:", data);

View File

@ -74,7 +74,7 @@ export class InAppNotificationEditorComponent extends BaseComponent implements O
if(!this.isDeleted && !this.isRead) this.markAsRead()
},
error => this.onCallbackError(error)
error => this.httpErrorHandlingService.handleBackedRequestError(error)
);
} else {
this.inappNotification = null;
@ -87,7 +87,7 @@ export class InAppNotificationEditorComponent extends BaseComponent implements O
this.inappNotificationService.read(value.id).pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCallbackSuccess(),
error => this.onCallbackError(error)
error => this.httpErrorHandlingService.handleBackedRequestError(error)
);
// this.clearErrorModel();
}
@ -109,7 +109,7 @@ export class InAppNotificationEditorComponent extends BaseComponent implements O
this.inappNotificationService.delete(value.id).pipe(takeUntil(this._destroyed))
.subscribe(
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.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();
}
private onCallbackError(errorResponse: HttpErrorResponse) {
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
goToNotification(item: InAppNotification) {
if (item.trackingState === NotificationInAppTracking.Stored) {
this.inappNotificationService.read(item.id)
@ -124,7 +119,7 @@ export class MineInAppNotificationListingDialogComponent extends BaseComponent i
data => {
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) {
this.notificationTrackingProcess = NotificationTrackingProcess.ERROR;
const error: HttpError = this.httpErrorHandlingService.getError(errorResponse);
if (error.statusCode === 400) {
} else {
this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning);
}
this.httpErrorHandlingService.handleBackedRequestError(errorResponse);
}
dropped(event: CdkDragDrop<string[]>, type: NotificationType) {