Skip to main content
zerotal

Documentation


Documentation / @zerotal/client / index / ValidationError

Class: ValidationError

Defined in: client/src/errors.ts:48

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

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

Constructors

Constructor

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

Defined in: client/src/errors.ts:54

Parameters

statusText

string

body

string

errors

Record<string, string[]>

validationMessage

string

headers?

Headers

Returns

ValidationError

Overrides

ApiClientError.constructor

Properties

headers

readonly headers: Headers | undefined

Defined in: client/src/errors.ts:11

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

Inherited from

ApiClientError.headers


statusText

readonly statusText: string

Defined in: client/src/errors.ts:15

Inherited from

ApiClientError.statusText


body

readonly body: string

Defined in: client/src/errors.ts:16

Inherited from

ApiClientError.body


errors

readonly errors: Record<string, string[]>

Defined in: client/src/errors.ts:50

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


validationMessage

readonly validationMessage: string

Defined in: client/src/errors.ts:52

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

Inherited from

ApiClientError.code


status

readonly status: number = 500

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

Inherited from

ApiClientError.status


context?

readonly optional context?: Record<string, unknown>

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

Inherited from

ApiClientError.context

Accessors

retryAfterMs

Get Signature

get retryAfterMs(): number | null

Defined in: client/src/errors.ts:28

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

Returns

number | null

Inherited from

ApiClientError.retryAfterMs

Methods

has()

has(field): boolean

Defined in: client/src/errors.ts:67

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

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

All field errors.

Returns

Record<string, string[]>


fields()

fields(): string[]

Defined in: client/src/errors.ts:82

The names of every field that failed.

Returns

string[]