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; 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; private ErrorDescription dmpNewVersionConflict;
public ErrorDescription getDmpNewVersionConflict() { public ErrorDescription getDmpNewVersionConflict() {
@ -65,6 +85,26 @@ public class ErrorThesaurusProperties {
this.dmpNewVersionConflict = dmpNewVersionConflict; 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 dmpBlueprintNewVersionConflict;
public ErrorDescription getDmpBlueprintNewVersionConflict() { public ErrorDescription getDmpBlueprintNewVersionConflict() {

View File

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

View File

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

View File

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

View File

@ -8,17 +8,21 @@ export enum ResponseErrorCode {
// TenantNameRequired = 109, not used // TenantNameRequired = 109, not used
TenantNotAllowed = 112, TenantNotAllowed = 112,
DescriptionTemplateNewVersionConflict = 113, DescriptionTemplateNewVersionConflict = 113,
DmpNewVersionConflict = 114, DescriptionTemplateIsNotFinalized = 114,
DmpIsFinalized = 115, MultipleDescriptionTemplateVersionsNotSupported = 115,
DmpCanNotChange = 116, DmpNewVersionConflict = 116,
DmpDescriptionTemplateCanNotChange = 117, DmpIsNotFinalized = 117,
InvalidDescriptionTemplate = 118, MultipleDmpVersionsNotSupported = 118,
DescriptionIsFinalized = 119, DmpIsFinalized = 119,
DmpBlueprintHasNoDescriptionTemplates = 120, DmpCanNotChange = 120,
DmpBlueprintNewVersionConflict = 121, DmpDescriptionTemplateCanNotChange = 121,
DmpDescriptionTemplateCanNotRemove = 122, InvalidDescriptionTemplate = 122,
TenantTampering = 123, DescriptionIsFinalized = 123,
TenantConfigurationTypeCanNotChange = 124, DmpBlueprintHasNoDescriptionTemplates = 124,
MultipleTenantConfigurationTypeNotAllowed = 125, DmpBlueprintNewVersionConflict = 125,
TenantCodeExists = 126, 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 { nameof } from 'ts-simple-nameof';
import { DescriptionCopyDialogComponent } from '../description-copy-dialog/description-copy-dialog.component'; import { DescriptionCopyDialogComponent } from '../description-copy-dialog/description-copy-dialog.component';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({ @Component({
@ -93,7 +94,8 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni
private fb: UntypedFormBuilder, private fb: UntypedFormBuilder,
private lockService: LockService, private lockService: LockService,
private analyticsService: AnalyticsService, private analyticsService: AnalyticsService,
private breadcrumbService: BreadcrumbService private breadcrumbService: BreadcrumbService,
private httpErrorHandlingService: HttpErrorHandlingService
) { ) {
super(); super();
} }
@ -144,6 +146,8 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni
// this.breadCrumbs = observableOf(breadCrumbs); // this.breadCrumbs = observableOf(breadCrumbs);
}, (error: any) => { }, (error: any) => {
this.httpErrorHandlingService.handleBackedRequestError(error);
if (error.status === 404) { if (error.status === 404) {
return this.onFetchingDeletedCallbackError('/descriptions/'); 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 }); // breadCrumbs.push({ parentComponentName: 'DescriptionListingComponent', label: this.description.label, url: '/descriptions/overview/public/' + this.description.id });
// this.breadCrumbs = observableOf(breadCrumbs); // this.breadCrumbs = observableOf(breadCrumbs);
}, (error: any) => { }, (error: any) => {
this.httpErrorHandlingService.handleBackedRequestError(error);
if (error.status === 404) { if (error.status === 404) {
return this.onFetchingDeletedCallbackError('/explore-descriptions'); return this.onFetchingDeletedCallbackError('/explore-descriptions');
} }
@ -200,12 +206,10 @@ export class DescriptionOverviewComponent extends BaseComponent implements OnIni
} }
onFetchingDeletedCallbackError(redirectRoot: string) { onFetchingDeletedCallbackError(redirectRoot: string) {
this.uiNotificationService.snackBarNotification(this.language.instant('DESCRIPTION-OVERVIEW.ERROR.DELETED-DESCRIPTION'), SnackBarNotificationLevel.Error);
this.router.navigate([redirectRoot]); this.router.navigate([redirectRoot]);
} }
onFetchingForbiddenCallbackError(redirectRoot: string) { onFetchingForbiddenCallbackError(redirectRoot: string) {
this.uiNotificationService.snackBarNotification(this.language.instant('DESCRIPTION-OVERVIEW.ERROR.FORBIDEN-DESCRIPTION'), SnackBarNotificationLevel.Error);
this.router.navigate([redirectRoot]); 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 { DmpInvitationDialogComponent } from '../invitation/dialog/dmp-invitation-dialog.component';
import { NewVersionDmpDialogComponent } from '../new-version-dialog/dmp-new-version-dialog.component'; import { NewVersionDmpDialogComponent } from '../new-version-dialog/dmp-new-version-dialog.component';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
@Component({ @Component({
selector: 'app-dmp-overview', selector: 'app-dmp-overview',
@ -105,7 +106,8 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
public fileTransformerService: FileTransformerService, public fileTransformerService: FileTransformerService,
private referenceTypeService: ReferenceTypeService, private referenceTypeService: ReferenceTypeService,
private analyticsService: AnalyticsService, private analyticsService: AnalyticsService,
private breadcrumbService: BreadcrumbService private breadcrumbService: BreadcrumbService,
private HttpErrorHandlingService: HttpErrorHandlingService
) { ) {
super(); 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 }); // breadCrumbs.push({ parentComponentName: 'DmpListingComponent', label: this.dmp.label, url: '/plans/overview/' + this.dmp.id });
// this.breadCrumbs = observableOf(breadCrumbs); // this.breadCrumbs = observableOf(breadCrumbs);
}, (error: any) => { }, (error: any) => {
this.HttpErrorHandlingService.handleBackedRequestError(error);
if (error.status === 404) { if (error.status === 404) {
return this.onFetchingDeletedCallbackError('/plans/'); 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 }); // breadCrumbs.push({ parentComponentName: 'DmpListingComponent', label: this.dmp.label, url: '/plans/overview/public/' + this.dmp.id });
// this.breadCrumbs = observableOf(breadCrumbs); // this.breadCrumbs = observableOf(breadCrumbs);
}, (error: any) => { }, (error: any) => {
this.HttpErrorHandlingService.handleBackedRequestError(error);
if (error.status === 404) { if (error.status === 404) {
return this.onFetchingDeletedCallbackError('/explore-plans'); return this.onFetchingDeletedCallbackError('/explore-plans');
} }
@ -212,12 +218,10 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
} }
onFetchingDeletedCallbackError(redirectRoot: string) { onFetchingDeletedCallbackError(redirectRoot: string) {
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-OVERVIEW.ERROR.DELETED-DMP'), SnackBarNotificationLevel.Error);
this.router.navigate([redirectRoot]); this.router.navigate([redirectRoot]);
} }
onFetchingForbiddenCallbackError(redirectRoot: string) { onFetchingForbiddenCallbackError(redirectRoot: string) {
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-OVERVIEW.ERROR.FORBIDEN-DMP'), SnackBarNotificationLevel.Error);
this.router.navigate([redirectRoot]); this.router.navigate([redirectRoot]);
} }

View File

@ -37,8 +37,12 @@
"MISSING-TENANT": "Tenant Selection Required. Please select a tenant before proceeding.", "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.", "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.", "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.", "DESCRIPTION-TEMPLATE-NEW-VERSION-CONFLICT": "You can create a new version only by selected 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-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-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-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.", "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) { handleBackedRequestError(errorResponse: HttpErrorResponse, messageOvverrides?: Map<number, string>, defaultNotificationLevel: SnackBarNotificationLevel = SnackBarNotificationLevel.Warning) {
const error: HttpError = this.getError(errorResponse); 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){ if(errorResponse.error.code === ResponseErrorCode.HashConflict){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.HASH-CONFLICT"), SnackBarNotificationLevel.Error); 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){ else if(errorResponse.error.code === ResponseErrorCode.DescriptionTemplateNewVersionConflict){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DESCRIPTION-TEMPLATE-NEW-VERSION-CONFLICT"), SnackBarNotificationLevel.Error); 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){ else if(errorResponse.error.code === ResponseErrorCode.DmpNewVersionConflict){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-NEW-VERSION-CONFLICT"), SnackBarNotificationLevel.Error); 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){ else if(errorResponse.error.code === ResponseErrorCode.DmpIsFinalized){
this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-IS-FINALIZED"), SnackBarNotificationLevel.Error); this.uiNotificationService.snackBarNotification(this.language.instant("GENERAL.BACKEND-ERRORS.DMP-IS-FINALIZED"), SnackBarNotificationLevel.Error);
} }