Skip to main content
zerotal

Documentation


Documentation / @zerotal/flow / index / ValidationError

Class: ValidationError

Defined in: flow/src/validation.ts:50

Error thrown by Component.validate() when one or more fields fail validation.

Remarks

Extends ZerotalError with code "E_VALIDATION" and HTTP status 422. The failing fields are carried on errors, a map of field name → array of human-readable messages. The Flow WebSocket handler catches this and re-renders the component with the populated error bag rather than surfacing it as a crash.

Example

try {
  this.validate();
} catch (err) {
  if (err instanceof ValidationError) {
    // err.errors === { email: ["The email field is required."] }
  }
}

Extends

Constructors

Constructor

new ValidationError(errors): ValidationError

Defined in: flow/src/validation.ts:52

Parameters

errors

Record<string, string[]>

Map of field name to its array of validation error messages.

Returns

ValidationError

Overrides

ZerotalError.constructor

Properties

code

readonly code: string

Defined in: core/src/errors/ZerotalError.ts:18

Inherited from

ZerotalError.code


status

readonly status: number = 500

Defined in: core/src/errors/ZerotalError.ts:19

Inherited from

ZerotalError.status


context?

readonly optional context?: Record<string, unknown>

Defined in: core/src/errors/ZerotalError.ts:20

Inherited from

ZerotalError.context


errors

readonly errors: Record<string, string[]>

Defined in: flow/src/validation.ts:52

Map of field name to its array of validation error messages.