From 09198fc1bfb928728cba696aaf6abca7508c4d71 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 24 Oct 2019 19:16:50 +0200 Subject: [PATCH] Error in form-error. --- .../angular/forms/form-error.component.ts | 6 ++++-- src/Squidex/app/framework/state.ts | 14 ++++++++------ src/Squidex/app/framework/utils/error.ts | 12 ------------ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Squidex/app/framework/angular/forms/form-error.component.ts b/src/Squidex/app/framework/angular/forms/form-error.component.ts index ab22b0d87..40aeaf3fe 100644 --- a/src/Squidex/app/framework/angular/forms/form-error.component.ts +++ b/src/Squidex/app/framework/angular/forms/form-error.component.ts @@ -7,15 +7,17 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; +import { ErrorDto } from '@app/framework/internal'; + @Component({ selector: 'sqx-form-error', template: ` -
+
`, changeDetection: ChangeDetectionStrategy.OnPush }) export class FormErrorComponent { @Input() - public error: string | null | undefined; + public error?: ErrorDto | null; } \ No newline at end of file diff --git a/src/Squidex/app/framework/state.ts b/src/Squidex/app/framework/state.ts index fedaf5c38..9aaefa80d 100644 --- a/src/Squidex/app/framework/state.ts +++ b/src/Squidex/app/framework/state.ts @@ -9,18 +9,16 @@ import { AbstractControl } from '@angular/forms'; import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { distinctUntilChanged, map, shareReplay } from 'rxjs/operators'; -import { ErrorDto, getDisplayMessage } from './utils/error'; +import { getRawValue } from './angular/forms/forms-helper'; +import { ErrorDto } from './utils/error'; import { ResourceLinks } from './utils/hateos'; - import { Types } from './utils/types'; -import { getRawValue } from './angular/forms/forms-helper'; - export interface FormState { submitted: boolean; - error?: string | null; + error?: ErrorDto | null; } export class Form { @@ -104,7 +102,11 @@ export class Form { } public submitFailed(error?: string | ErrorDto) { - this.state.next({ submitted: false, error: getDisplayMessage(error) }); + if (Types.isString(error)) { + error = new ErrorDto(500, error); + } + + this.state.next({ submitted: false, error }); this.enable(); } diff --git a/src/Squidex/app/framework/utils/error.ts b/src/Squidex/app/framework/utils/error.ts index cb4546e4f..1b1e07aba 100644 --- a/src/Squidex/app/framework/utils/error.ts +++ b/src/Squidex/app/framework/utils/error.ts @@ -5,8 +5,6 @@ * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. */ -import { Types } from './types'; - export class ErrorDto { public readonly displayMessage: string; @@ -24,16 +22,6 @@ export class ErrorDto { } } -export function getDisplayMessage(error?: string | ErrorDto) { - if (!error) { - return null; - } else if (Types.is(error, ErrorDto)) { - return error.displayMessage; - } else { - return error; - } -} - function formatMessage(message: string, details?: ReadonlyArray) { const appendLast = (row: string, char: string) => { const last = row[row.length - 1];