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

***

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

# Class: ValidationError

Defined in: [client/src/errors.ts:48](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L48)

Thrown for `422 Unprocessable Entity` responses whose body matches the framework's
validation shape (`{ message, errors: { field: string[] } }`, as produced by
`@zerotal/validator`). Use the helpers to read field errors without re-parsing:

## Example

```ts
try {
  await api.post("/api/users", form);
} catch (e) {
  if (e instanceof ValidationError) {
    setFieldErrors(e.errors);          // { email: ["…"], password: ["…"] }
    if (e.has("email")) showError(e.first("email"));
  }
}
```

## Extends

- [`ApiClientError`](ApiClientError)

## Constructors

### Constructor

> **new ValidationError**(`statusText`, `body`, `errors`, `validationMessage`, `headers?`): `ValidationError`

Defined in: [client/src/errors.ts:54](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L54)

#### Parameters

##### statusText

`string`

##### body

`string`

##### errors

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

##### validationMessage

`string`

##### headers?

`Headers`

#### Returns

`ValidationError`

#### Overrides

[`ApiClientError`](ApiClientError).[`constructor`](ApiClientError#constructor)

## Properties

### headers

> `readonly` **headers**: `Headers` \| `undefined`

Defined in: [client/src/errors.ts:11](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L11)

Response headers, when available (used for `Retry-After`, rate-limit info, etc.).

#### Inherited from

[`ApiClientError`](ApiClientError).[`headers`](ApiClientError#headers)

***

### statusText

> `readonly` **statusText**: `string`

Defined in: [client/src/errors.ts:15](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L15)

#### Inherited from

[`ApiClientError`](ApiClientError).[`statusText`](ApiClientError#statustext)

***

### body

> `readonly` **body**: `string`

Defined in: [client/src/errors.ts:16](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L16)

#### Inherited from

[`ApiClientError`](ApiClientError).[`body`](ApiClientError#body)

***

### errors

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

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

Field → messages map (always an array per field).

***

### validationMessage

> `readonly` **validationMessage**: `string`

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

The top-level `message` from the response (e.g. "The given data was invalid.").

***

### 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

[`ApiClientError`](ApiClientError).[`code`](ApiClientError#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

[`ApiClientError`](ApiClientError).[`status`](ApiClientError#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

[`ApiClientError`](ApiClientError).[`context`](ApiClientError#context)

## Accessors

### retryAfterMs

#### Get Signature

> **get** **retryAfterMs**(): `number` \| `null`

Defined in: [client/src/errors.ts:28](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L28)

Parsed `Retry-After` (seconds or HTTP-date) in milliseconds, or `null` when absent.

##### Returns

`number` \| `null`

#### Inherited from

[`ApiClientError`](ApiClientError).[`retryAfterMs`](ApiClientError#retryafterms)

## Methods

### has()

> **has**(`field`): `boolean`

Defined in: [client/src/errors.ts:67](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L67)

True when the given field has at least one error.

#### Parameters

##### field

`string`

#### Returns

`boolean`

***

### first()

> **first**(`field`): `string` \| `undefined`

Defined in: [client/src/errors.ts:72](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L72)

The first error message for a field, or `undefined`.

#### Parameters

##### field

`string`

#### Returns

`string` \| `undefined`

***

### all()

> **all**(): `Record`\<`string`, `string`[]\>

Defined in: [client/src/errors.ts:77](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L77)

All field errors.

#### Returns

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

***

### fields()

> **fields**(): `string`[]

Defined in: [client/src/errors.ts:82](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/client/src/errors.ts#L82)

The names of every field that failed.

#### Returns

`string`[]
