[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/flow](../../README) / [index](../README) / ValidationError

# Class: ValidationError

Defined in: [flow/src/validation.ts:50](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/validation.ts#L50)

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

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

## Extends

- [`ZerotalError`](../../../core/index/classes/ZerotalError)

## Constructors

### Constructor

> **new ValidationError**(`errors`): `ValidationError`

Defined in: [flow/src/validation.ts:52](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/validation.ts#L52)

#### Parameters

##### errors

`Record`\<`string`, `string`[]\>

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

#### Returns

`ValidationError`

#### Overrides

[`ZerotalError`](../../../core/index/classes/ZerotalError).[`constructor`](../../../core/index/classes/ZerotalError#constructor)

## Properties

### code

> `readonly` **code**: `string`

Defined in: [core/src/errors/ZerotalError.ts:18](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/errors/ZerotalError.ts#L18)

#### Inherited from

[`ZerotalError`](../../../core/index/classes/ZerotalError).[`code`](../../../core/index/classes/ZerotalError#code)

***

### status

> `readonly` **status**: `number` = `500`

Defined in: [core/src/errors/ZerotalError.ts:19](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/errors/ZerotalError.ts#L19)

#### Inherited from

[`ZerotalError`](../../../core/index/classes/ZerotalError).[`status`](../../../core/index/classes/ZerotalError#status)

***

### context?

> `readonly` `optional` **context?**: `Record`\<`string`, `unknown`\>

Defined in: [core/src/errors/ZerotalError.ts:20](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/errors/ZerotalError.ts#L20)

#### Inherited from

[`ZerotalError`](../../../core/index/classes/ZerotalError).[`context`](../../../core/index/classes/ZerotalError#context)

***

### errors

> `readonly` **errors**: `Record`\<`string`, `string`[]\>

Defined in: [flow/src/validation.ts:52](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/validation.ts#L52)

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