Browse Source

Error in form-error.

release/3.x
Sebastian 6 years ago
parent
commit
09198fc1bf
  1. 6
      src/Squidex/app/framework/angular/forms/form-error.component.ts
  2. 14
      src/Squidex/app/framework/state.ts
  3. 12
      src/Squidex/app/framework/utils/error.ts

6
src/Squidex/app/framework/angular/forms/form-error.component.ts

@ -7,15 +7,17 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ErrorDto } from '@app/framework/internal';
@Component({ @Component({
selector: 'sqx-form-error', selector: 'sqx-form-error',
template: ` template: `
<ng-container *ngIf="error"> <ng-container *ngIf="error">
<div class="form-alert form-alert-error" [innerHTML]="error"></div> <div class="form-alert form-alert-error" [innerHTML]="error?.displayMessage"></div>
</ng-container>`, </ng-container>`,
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class FormErrorComponent { export class FormErrorComponent {
@Input() @Input()
public error: string | null | undefined; public error?: ErrorDto | null;
} }

14
src/Squidex/app/framework/state.ts

@ -9,18 +9,16 @@ import { AbstractControl } from '@angular/forms';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
import { distinctUntilChanged, map, shareReplay } from 'rxjs/operators'; 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 { ResourceLinks } from './utils/hateos';
import { Types } from './utils/types'; import { Types } from './utils/types';
import { getRawValue } from './angular/forms/forms-helper';
export interface FormState { export interface FormState {
submitted: boolean; submitted: boolean;
error?: string | null; error?: ErrorDto | null;
} }
export class Form<T extends AbstractControl, V> { export class Form<T extends AbstractControl, V> {
@ -104,7 +102,11 @@ export class Form<T extends AbstractControl, V> {
} }
public submitFailed(error?: string | ErrorDto) { 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(); this.enable();
} }

12
src/Squidex/app/framework/utils/error.ts

@ -5,8 +5,6 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/ */
import { Types } from './types';
export class ErrorDto { export class ErrorDto {
public readonly displayMessage: string; 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<string>) { function formatMessage(message: string, details?: ReadonlyArray<string>) {
const appendLast = (row: string, char: string) => { const appendLast = (row: string, char: string) => {
const last = row[row.length - 1]; const last = row[row.length - 1];

Loading…
Cancel
Save