error handling refactoring: added new errors, fixed translations and fixed error handling on overviews

This commit is contained in:
Sofia Papacharalampous 2024-06-03 12:18:42 +03:00
parent 13db96b770
commit 280975679f
9 changed files with 120 additions and 40 deletions

View File

@ -55,6 +55,26 @@ public class ErrorThesaurusProperties {
this.descriptionTemplateNewVersionConflict = descriptionTemplateNewVersionConflict;
}
private ErrorDescription descriptionTemplateIsNotFinalized;
public ErrorDescription getDescriptionTemplateIsNotFinalized() {
return this.descriptionTemplateIsNotFinalized;
}
public void setDescriptionTemplateIsNotFinalized(ErrorDescription descriptionTemplateIsNotFinalized) {
this.descriptionTemplateIsNotFinalized = descriptionTemplateIsNotFinalized;
}
private ErrorDescription multipleDescriptionTemplateVersionsNotSupported;
public ErrorDescription getMultipleDescriptionTemplateVersionsNotSupported() {
return this.multipleDescriptionTemplateVersionsNotSupported;
}
public void setMultipleDescriptionTemplateVersionsNotSupported(ErrorDescription multipleDescriptionTemplateVersionsNotSupported) {
this.multipleDescriptionTemplateVersionsNotSupported = multipleDescriptionTemplateVersionsNotSupported;
}
private ErrorDescription dmpNewVersionConflict;
public ErrorDescription getDmpNewVersionConflict() {
@ -65,6 +85,26 @@ public class ErrorThesaurusProperties {
this.dmpNewVersionConflict = dmpNewVersionConflict;
}
private ErrorDescription dmpIsNotFinalized;
public ErrorDescription getDmpIsNotFinalized() {
return this.dmpIsNotFinalized;
}
public void setDmpIsNotFinalized(ErrorDescription dmpIsNotFinalized) {
this.dmpIsNotFinalized = dmpIsNotFinalized;
}
private ErrorDescription multipleDmpVersionsNotSupported;
public ErrorDescription getMultipleDmpVersionsNotSupported() {
return this.multipleDmpVersionsNotSupported;
}
public void setMultipleDmpVersionsNotSupported(ErrorDescription multipleDmpVersionsNotSupported) {
this.multipleDmpVersionsNotSupported = multipleDmpVersionsNotSupported;
}
public ErrorDescription dmpBlueprintNewVersionConflict;
public ErrorDescription getDmpBlueprintNewVersionConflict() {

View File

@ -682,9 +682,9 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
.groupIds(oldDescriptionTemplateEntity.getGroupId())
.collect();
if (latestVersionDescriptionTemplates.isEmpty())
throw new MyValidationException("Previous template not found");
throw new MyValidationException(this.errors.getDescriptionTemplateIsNotFinalized().getCode());
if (latestVersionDescriptionTemplates.size() > 1)
throw new MyValidationException("Multiple previous template found");
throw new MyValidationException(this.errors.getMultipleDmpVersionsNotSupported().getCode());
if (!latestVersionDescriptionTemplates.getFirst().getVersion().equals(oldDescriptionTemplateEntity.getVersion()))
throw new MyValidationException(this.errors.getDescriptionTemplateNewVersionConflict().getCode(), this.errors.getDescriptionTemplateNewVersionConflict().getMessage());
Long notFinalizedCount = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking()

View File

@ -398,8 +398,8 @@ public class DmpServiceImpl implements DmpService {
.isActive(IsActive.Active)
.versionStatuses(DmpVersionStatus.Current)
.collect();
if (latestVersionDmps.isEmpty()) throw new MyValidationException("Previous dmp not found");
if (latestVersionDmps.size() > 1) throw new MyValidationException("Multiple previous dmps found");
if (latestVersionDmps.isEmpty()) throw new MyValidationException(this.errors.getDmpIsNotFinalized().getCode());
if (latestVersionDmps.size() > 1) throw new MyValidationException(this.errors.getMultipleDmpVersionsNotSupported().getCode());
if (!latestVersionDmps.getFirst().getVersion().equals(oldDmpEntity.getVersion())){
throw new MyValidationException(this.errors.getDmpNewVersionConflict().getCode(), this.errors.getDmpNewVersionConflict().getMessage());
}

View File

@ -29,42 +29,54 @@ error-thesaurus:
description-template-new-version-conflict:
code: 113
message: version to update not the latest
dmp-new-version-conflict:
description-template-is-not-finalized:
code: 114
message: version to update not the latest
dmp-is-finalized:
message: the selected description template is not finalized
multiple-description-template-versions-not-supported:
code: 115
message: multiple versions of the selected description where found
dmp-new-version-conflict:
code: 116
message: version to update not the latest
dmp-is-not-finalized:
code: 117
message: the selected dmp is not finalized
multiple-dmp-versions-not-supported:
code: 118
message: multiple versions of the dmp where found
dmp-is-finalized:
code: 119
message: To perform this action you will need to revert DMP's finalisation
dmp-can-not-change:
code: 116
code: 120
message: dmp can not change
dmp-description-template-can-not-change:
code: 117
code: 121
message: dmp description template can not change
invalid-description-template:
code: 118
code: 122
message: invalid description template id
description-is-finalized:
code: 119
code: 123
message: To perform this action you will need to revert description finalisation
dmp-blueprint-has-no-description-templates:
code: 120
code: 124
message: You need to select Has Description Templates field to at least one Section.
dmp-blueprint-new-version-conflict:
code: 121
code: 125
message: version to update not the latest
dmp-description-template-can-not-remove:
code: 122
code: 126
message: Can not remove description template that is already in use.
tenant-tampering:
code: 123
code: 127
message: Tenant tampering
tenant-configuration-type-can-not-change:
code: 124
code: 128
message: Tenant configuration type can not change
multiple-tenant-configuration-type-not-allowed:
code: 125
code: 129
message: Multiple Tenant Configuration Type Not Allowed
tenant-code-exists:
code: 126
code: 130
message: Tenant code exists

View File

@ -8,17 +8,21 @@ export enum ResponseErrorCode {
// 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,
TenantTampering = 123,
TenantConfigurationTypeCanNotChange = 124,
MultipleTenantConfigurationTypeNotAllowed = 125,
TenantCodeExists = 126,
DescriptionTemplateIsNotFinalized = 114,
MultipleDescriptionTemplateVersionsNotSupported = 115,
DmpNewVersionConflict = 116,
DmpIsNotFinalized = 117,
MultipleDmpVersionsNotSupported = 118,
DmpIsFinalized = 119,
DmpCanNotChange = 120,
DmpDescriptionTemplateCanNotChange = 121,
InvalidDescriptionTemplate = 122,
DescriptionIsFinalized = 123,
DmpBlueprintHasNoDescriptionTemplates = 124,
DmpBlueprintNewVersionConflict = 125,
DmpDescriptionTemplateCanNotRemove = 126,
TenantTampering = 127,
TenantConfigurationTypeCanNotChange = 128,
MultipleTenantConfigurationTypeNotAllowed = 129,
TenantCodeExists = 130,
}

View File

@ -41,6 +41,7 @@ import { takeUntil } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
import { DescriptionCopyDialogComponent } from '../description-copy-dialog/description-copy-dialog.component';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({
@ -93,7 +94,8 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni
private fb: UntypedFormBuilder,
private lockService: LockService,
private analyticsService: AnalyticsService,
private breadcrumbService: BreadcrumbService
private breadcrumbService: BreadcrumbService,
private httpErrorHandlingService: HttpErrorHandlingService
) {
super();
}
@ -144,6 +146,8 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni
// this.breadCrumbs = observableOf(breadCrumbs);
}, (error: any) => {
this.httpErrorHandlingService.handleBackedRequestError(error);
if (error.status === 404) {
return this.onFetchingDeletedCallbackError('/descriptions/');
}
@ -169,6 +173,8 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni
// breadCrumbs.push({ parentComponentName: 'DescriptionListingComponent', label: this.description.label, url: '/descriptions/overview/public/' + this.description.id });
// this.breadCrumbs = observableOf(breadCrumbs);
}, (error: any) => {
this.httpErrorHandlingService.handleBackedRequestError(error);
if (error.status === 404) {
return this.onFetchingDeletedCallbackError('/explore-descriptions');
}
@ -200,12 +206,10 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni
}
onFetchingDeletedCallbackError(redirectRoot: string) {
this.uiNotificationService.snackBarNotification(this.language.instant('DESCRIPTION-OVERVIEW.ERROR.DELETED-DESCRIPTION'), SnackBarNotificationLevel.Error);
this.router.navigate([redirectRoot]);
}
onFetchingForbiddenCallbackError(redirectRoot: string) {
this.uiNotificationService.snackBarNotification(this.language.instant('DESCRIPTION-OVERVIEW.ERROR.FORBIDEN-DESCRIPTION'), SnackBarNotificationLevel.Error);
this.router.navigate([redirectRoot]);
}

View File

@ -50,6 +50,7 @@ import { DmpFinalizeDialogComponent, DmpFinalizeDialogOutput } from '../dmp-fina
import { DmpInvitationDialogComponent } from '../invitation/dialog/dmp-invitation-dialog.component';
import { NewVersionDmpDialogComponent } from '../new-version-dialog/dmp-new-version-dialog.component';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({
selector: 'app-dmp-overview',
@ -105,7 +106,8 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
public fileTransformerService: FileTransformerService,
private referenceTypeService: ReferenceTypeService,
private analyticsService: AnalyticsService,
private breadcrumbService: BreadcrumbService
private breadcrumbService: BreadcrumbService,
private HttpErrorHandlingService: HttpErrorHandlingService
) {
super();
}
@ -150,6 +152,8 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
// breadCrumbs.push({ parentComponentName: 'DmpListingComponent', label: this.dmp.label, url: '/plans/overview/' + this.dmp.id });
// this.breadCrumbs = observableOf(breadCrumbs);
}, (error: any) => {
this.HttpErrorHandlingService.handleBackedRequestError(error);
if (error.status === 404) {
return this.onFetchingDeletedCallbackError('/plans/');
}
@ -179,6 +183,8 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
// breadCrumbs.push({ parentComponentName: 'DmpListingComponent', label: this.dmp.label, url: '/plans/overview/public/' + this.dmp.id });
// this.breadCrumbs = observableOf(breadCrumbs);
}, (error: any) => {
this.HttpErrorHandlingService.handleBackedRequestError(error);
if (error.status === 404) {
return this.onFetchingDeletedCallbackError('/explore-plans');
}
@ -212,12 +218,10 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
}
onFetchingDeletedCallbackError(redirectRoot: string) {
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-OVERVIEW.ERROR.DELETED-DMP'), SnackBarNotificationLevel.Error);
this.router.navigate([redirectRoot]);
}
onFetchingForbiddenCallbackError(redirectRoot: string) {
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-OVERVIEW.ERROR.FORBIDEN-DMP'), SnackBarNotificationLevel.Error);
this.router.navigate([redirectRoot]);
}

View File

@ -37,8 +37,12 @@
"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. Please reselect your 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.",
"DESCRIPTION-TEMPLATE-NEW-VERSION-CONFLICT": "You can create a new version only by selected the latest version.",
"DESCRIPTION-TEMPLATE-IS-NOT-FINALIZED": "The selected Description Template is not finalized.",
"MULTIPLE-DESCRIPTION-TEMPLATE-VERSIONS-NOT-SUPPORTED": "Multiple versions of the selected Description Template where found. Please contact your administrator.",
"DMP-NEW-VERSION-CONFLICT": "You can create a new version only by selected the latest version.",
"DMP-IS-NOT-FINALIZED": "The selected DMP is not finalized.",
"MULTIPLE-DMP-VERSIONS-NOT-SUPPORTED": "Multiple versions of the selected DMP where found. Please contact your administrator.",
"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.",

View File

@ -14,7 +14,7 @@ export class HttpErrorHandlingService {
handleBackedRequestError(errorResponse: HttpErrorResponse, messageOvverrides?: Map<number, string>, defaultNotificationLevel: SnackBarNotificationLevel = SnackBarNotificationLevel.Warning) {
const error: HttpError = this.getError(errorResponse);
let errorMessage = messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : '';
let errorMessage = messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : null;
if(errorResponse.error.code === ResponseErrorCode.HashConflict){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.HASH-CONFLICT"), SnackBarNotificationLevel.Error);
@ -37,9 +37,21 @@ export class HttpErrorHandlingService {
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.DescriptionTemplateIsNotFinalized){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DESCRIPTION-TEMPLATE-IS-NOT-FINALIZED"), SnackBarNotificationLevel.Error);
}
else if(errorResponse.error.code === ResponseErrorCode.MultipleDescriptionTemplateVersionsNotSupported){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.MULTIPLE-DESCRIPTION-TEMPLATE-VERSIONS-NOT-SUPPORTED"), 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.DmpIsNotFinalized){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-IS-NOT-FINALIZED"), SnackBarNotificationLevel.Error);
}
else if(errorResponse.error.code === ResponseErrorCode.MultipleDmpVersionsNotSupported){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.MULTIPLE-DMP-VERSIONS-NOT-SUPPORTED"), SnackBarNotificationLevel.Error);
}
else if(errorResponse.error.code === ResponseErrorCode.DmpIsFinalized){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-IS-FINALIZED"), SnackBarNotificationLevel.Error);
}