OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#41944] fixed parsing of error messages of hal errors
Eric Schubert08d505c0dedd
diff --git a/frontend/src/app/features/hal/resources/error-resource.ts b/frontend/src/app/features/hal/resources/error-resource.tsindex a69732c7b13..92555e95a12 100644--- a/frontend/src/app/features/hal/resources/error-resource.ts+++ b/frontend/src/app/features/hal/resources/error-resource.ts@@ -38,6 +38,11 @@ export interface IHalErrorBase {errorIdentifier:string;}+// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any+export function isHalError(err:any):err is IHalErrorBase {+ return '_type' in err && 'message' in err && 'errorIdentifier' in err;+}+export interface IHalSingleError extends IHalErrorBase {_embedded:{details:{@@ -70,7 +75,7 @@ export class ErrorResource extends HalResource {* Override toString to ensure the resource can* be printed nicely on console and in errors*/- public toString() {+ public toString():string {return `[ErrorResource ${this.message}]`;}@@ -82,7 +87,7 @@ export class ErrorResource extends HalResource {return [this.message];}- public isMultiErrorMessage() {+ public isMultiErrorMessage():boolean {return this.errorIdentifier === v3ErrorIdentifierMultipleErrors;}diff --git a/frontend/src/app/shared/components/toaster/toast.service.ts b/frontend/src/app/shared/components/toaster/toast.service.tsindex 29915466768..475fa7b3f40 100644--- a/frontend/src/app/shared/components/toaster/toast.service.ts+++ b/frontend/src/app/shared/components/toaster/toast.service.ts@@ -36,12 +36,13 @@ import { UploadInProgress } from 'core-app/core/file-upload/op-file-upload.serviimport {IHalErrorBase,IHalMultipleError,+ isHalError,} from 'core-app/features/hal/resources/error-resource';import { HttpErrorResponse } from '@angular/common/http';import { Observable } from 'rxjs';import { I18nService } from 'core-app/core/i18n/i18n.service';-export function removeSuccessFlashMessages() {+export function removeSuccessFlashMessages():void {jQuery('.flash.notice').remove();}@@ -50,7 +51,7 @@ export const OPToastEvent = 'op:toasters:add';export interface IToast {message:string;- link?:{ text:string, target:Function };+ link?:{ text:string, target:() => void };type:ToastType;data?:unknown;}@@ -110,14 +111,17 @@ export class ToastService {errors = [...additionalErrors] as string[];}- if (obj instanceof HttpErrorResponse && (obj.error as IHalMultipleError)?._embedded?.errors) {- errors = [- ...errors,- ...(obj.error as IHalMultipleError)._embedded.errors.map((el:IHalErrorBase) => el.message),- ];- message = obj.message;+ if (obj instanceof HttpErrorResponse) {+ message = isHalError(obj.error) ? obj.error.message : obj.message;++ if ((obj.error as IHalMultipleError)?._embedded?.errors) {+ errors = [+ ...errors,+ ...(obj.error as IHalMultipleError)._embedded.errors.map((el:IHalErrorBase) => el.message),+ ];+ }} else {- message = obj as IToast|string;+ message = obj;}const toast:IToast = this.createToast(message, 'error');@@ -158,12 +162,7 @@ export class ToastService {}private createToast(message:IToast|string, type:ToastType):IToast {- if (typeof message === 'string') {- return { message, type };- }- message.type = type;-- return message;+ return (typeof message === 'string') ? { message, type } : { message: message.message, type };}private createAttachmentUploadToast(message:IToast|string, uploads:UploadInProgress[]) {