From 46347d458365a057fc75e90bf164de2de25ccf81 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Fri, 31 May 2024 13:47:32 +0300 Subject: [PATCH] error handling refactoring --- .../web/src/main/resources/config/errors.yml | 30 +++---- .../core/common/enum/respone-error-code.ts | 20 +++-- dmp-frontend/src/assets/i18n/en.json | 25 +++++- .../http-error-handling.service.ts | 89 +++++++++++++------ 4 files changed, 115 insertions(+), 49 deletions(-) diff --git a/backend/web/src/main/resources/config/errors.yml b/backend/web/src/main/resources/config/errors.yml index 9409cad3c..90c7c472c 100644 --- a/backend/web/src/main/resources/config/errors.yml +++ b/backend/web/src/main/resources/config/errors.yml @@ -14,32 +14,32 @@ error-thesaurus: model-validation: code: 106 message: validation error - tenant-code-required: - code: 108 - message: tenant code required - tenant-name-required: - code: 109 - message: tenant name required - index-already-exists: - code: 110 - message: index already exists +# tenant-code-required: +# code: 108 +# message: tenant code required +# tenant-name-required: +# code: 109 +# message: tenant name required +# index-already-exists: +# code: 110 +# message: index already exists tenant-not-allowed: - code: 113 + code: 112 message: tenant not allowed description-template-new-version-conflict: - code: 114 + code: 113 message: version to update not the latest dmp-new-version-conflict: - code: 115 + code: 114 message: version to update not the latest dmp-is-finalized: - code: 116 + code: 115 message: To perform this action you will need to revert DMP's finalisation dmp-can-not-change: - code: 117 + code: 116 message: dmp can not change dmp-description-template-can-not-change: - code: 118 + code: 117 message: dmp description template can not change invalid-description-template: code: 118 diff --git a/dmp-frontend/src/app/core/common/enum/respone-error-code.ts b/dmp-frontend/src/app/core/common/enum/respone-error-code.ts index bf367108d..8c9f66b20 100644 --- a/dmp-frontend/src/app/core/common/enum/respone-error-code.ts +++ b/dmp-frontend/src/app/core/common/enum/respone-error-code.ts @@ -1,15 +1,19 @@ export enum ResponseErrorCode { HashConflict = 100, Forbidden = 101, - SystemError =102, + SystemError = 102, MissingTenant = 103, - TenantCodeRequired = 108, - TenantNameRequired = 109, - TenantNotAllowed = 113, - DescriptionTemplateNewVersionConflict = 114, - DmpNewVersionConflict = 115, - DmpIsFinalized = 116, - + ΜodelValidation = 106, + // TenantCodeRequired = 108, not used + // TenantNameRequired = 109, not used + TenantNotAllowed = 112, + DescriptionTemplateNewVersionConflict = 113, + DmpNewVersionConflict = 114, + DmpIsFinalized = 115, + DmpCanNotChange = 116, + DmpDescriptionTemplateCanNotChange = 117, + InvalidDescriptionTemplate = 118, + DescriptionIsFinalized = 119, DmpBlueprintHasNoDescriptionTemplates = 120, DmpBlueprintNewVersionConflict = 121, DmpDescriptionTemplateCanNotRemove = 122, diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index 2ebe64289..086451f1e 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -24,11 +24,34 @@ "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", - "NOT-FOUND": "The page you are looking for doesn't exist." + "NOT-FOUND": "The page you are looking for doesn't exist.", + "GENERIC-ERROR": "Something unexpected occurred. Please try again later." }, "ERRORS": { "HTTP-REQUEST-ERROR": "An Unexpected Error Has Occurred" }, + "BACKEND-ERRORS": { + "HASH-CONFLICT": "It looks like someone else has made changes to this page. Please reload to view the latest updates.", + "FORBIDDEN": "You do not have the necessary permissions to view this page.", + "SYSTEM-ERROR": "An unexpected error has occurred. Please try again later.", + "MISSING-TENANT": "Tenant Selection Required. Please select a tenant before proceeding.", + "MODEL-VALIDATION": "One or more fields contain invalid data. Please check your input and try again.", + "TENANT-NOT-ALLOWED": "You are not allowed to access this page based on your associated tenant.", + "DESCRIPTION-TEMPLATE-NEW-VERSION-CONFLICT": "While trying to update your Description, a version conflict occurred. Your Description is not in the latest version.", + "DMP-NEW-VERSION-CONFLICT": "While trying to update your DMP, a version conflict occurred. Your DMP is not in the latest version.", + "DMP-IS-FINALIZED": "The requested action cannot be completed as the DMP has been finalized. To proceed, please revert the finalization.", + "DMP-CAN-NOT-CHANGE": "While tying to update your Description, a validation error occured. You cannot modify the Description's associated DMP.", + "DMP-DESCRIPTION-TEMPLATE-CAN-NOT-CHANGE": "While tying to update your Description, a validation error occured. You cannot modify the Description's associated DMP's Description Template.", + "INVALID-DESCRIPTION-TEMPLATE": "While tying to update your Description, a validation error occured. The Description's associated DMP's Description Template is invalid.", + "DESCRIPTION-IS-FINALIZED": "The requested action cannot be completed as the Description has been finalized. To proceed, please revert the finalization.", + "DMP-BLUEPRINT-HAS-NO-DESCRIPTION-TEMPLATES": "You need to select at least one Description Template. Click the 'Has Description Templates' button to proceed.", + "DMP-BLUEPRINT-NEW-VERSION-CONFLICT": "While trying to update your Blueprint, a version conflict occurred. Your Blueprint is not in the latest version.", + "DMP-DESCRIPTION-TEMPLATE-CAN-NOT-REMOVE": "The Description template cannot be removed as it is currently in use.", + "TENANT-TAMPERING": "While trying to process your request, a conflict has occurred related to the selected Tenant. Please try again later.", + "TENANT-CONFIGURATION-TYPE-CAN-NOT-CHANGE": "The configuration type for this Tenant cannot be changed.", + "MULTIPLE-TENANT-CONFIGURATION-TYPE-NOT-ALLOWED": "Multiple configurations are not permitted for this Tenant.", + "TENANT-CODE-EXISTS": "The Tenant code you provided already exists. Please choose a different code." + }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warning!", "THIS-FIELD": "Field", diff --git a/dmp-frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts b/dmp-frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts index e3f033dc0..4b25697a0 100644 --- a/dmp-frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts +++ b/dmp-frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts @@ -14,36 +14,75 @@ export class HttpErrorHandlingService { handleBackedRequestError(errorResponse: HttpErrorResponse, messageOvverrides?: Map, defaultNotificationLevel: SnackBarNotificationLevel = SnackBarNotificationLevel.Warning) { const error: HttpError = this.getError(errorResponse); - let errorMessage = messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : 'NOT-FOUND'; + let errorMessage = messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : ''; - 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(errorResponse.error.code === ResponseErrorCode.HashConflict){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.HASH-CONFLICT"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.Forbidden){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.FORBIDDEN"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.SystemError){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.SYSTEM-ERROR"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.MissingTenant){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.MISSING-TENANT"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.ΜodelValidation){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.MODEL-VALIDATION"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.TenantNotAllowed){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.TENANT-NOT-ALLOWED"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.DescriptionTemplateNewVersionConflict){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DESCRIPTION-TEMPLATE-NEW-VERSION-CONFLICT"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.DmpNewVersionConflict){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-NEW-VERSION-CONFLICT"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.DmpIsFinalized){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-IS-FINALIZED"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.DmpCanNotChange){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-CAN-NOT-CHANGE"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.DmpDescriptionTemplateCanNotChange){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-DESCRIPTION-TEMPLATE-CAN-NOT-CHANGE"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.InvalidDescriptionTemplate){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.INVALID-DESCRIPTION-TEMPLATE"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.DescriptionIsFinalized){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DESCRIPTION-IS-FINALIZED"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.DmpBlueprintHasNoDescriptionTemplates){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-BLUEPRINT-HAS-NO-DESCRIPTION-TEMPLATES"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.DmpBlueprintNewVersionConflict){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-BLUEPRINT-NEW-VERSION-CONFLICT"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.DmpDescriptionTemplateCanNotRemove){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-DESCRIPTION-TEMPLATE-CAN-NOT-REMOVE"), SnackBarNotificationLevel.Error); } - if (error.statusCode === 302 || error.statusCode === 404) { + else if(errorResponse.error.code === ResponseErrorCode.TenantTampering){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.TENANT-TAMPERING"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.TenantConfigurationTypeCanNotChange){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.TENANT-CONFIGURATION-TYPE-CAN-NOT-CHANGE"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.MultipleTenantConfigurationTypeNotAllowed){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.MULTIPLE-TENANT-CONFIGURATION-TYPE-NOT-ALLOWED"), SnackBarNotificationLevel.Error); + } + else if(errorResponse.error.code === ResponseErrorCode.TenantCodeExists){ + this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.TENANT-CODE-EXISTS"), SnackBarNotificationLevel.Error); + } + else if (error.statusCode === 302 || error.statusCode === 400 || error.statusCode === 404) { + errorMessage ??= this.language.instant('GENERAL.SNACK-BAR.NOT-FOUND'); this.uiNotificationService.snackBarNotification(errorMessage, SnackBarNotificationLevel.Warning); } else { - let errorMessage = messageOvverrides?.has(-1) ? messageOvverrides?.get(error.statusCode) : error.getMessagesString(); + errorMessage = messageOvverrides?.has(-1) ? + messageOvverrides?.get(error.statusCode) : this.language.instant('GENERAL.SNACK-BAR.GENERIC-ERROR'); this.uiNotificationService.snackBarNotification(errorMessage, defaultNotificationLevel); } }