Documentation / zerotal / client / ValidationError
Class: ValidationError
Defined in: packages/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: packages/client/src/errors.ts:54
Parameters
statusText
string
body
string
errors
Record<string, string[]>
validationMessage
string
headers?
Headers
Returns
ValidationError
Overrides
Properties
headers
readonlyheaders:Headers|undefined
Defined in: packages/client/src/errors.ts:11
Response headers, when available (used for Retry-After, rate-limit info, etc.).
Inherited from
statusText
readonlystatusText:string
Defined in: packages/client/src/errors.ts:15
Inherited from
body
readonlybody:string
Defined in: packages/client/src/errors.ts:16
Inherited from
errors
readonlyerrors:Record<string,string[]>
Defined in: packages/client/src/errors.ts:50
Field → messages map (always an array per field).
validationMessage
readonlyvalidationMessage:string
Defined in: packages/client/src/errors.ts:52
The top-level message from the response (e.g. "The given data was invalid.").
code
readonlycode:string
Defined in: packages/core/src/errors/ZerotalError.ts:18
Inherited from
status
readonlystatus:number=500
Defined in: packages/core/src/errors/ZerotalError.ts:19
Inherited from
context?
readonlyoptionalcontext?:Record<string,unknown>
Defined in: packages/core/src/errors/ZerotalError.ts:20
Inherited from
Accessors
retryAfterMs
Get Signature
get retryAfterMs():
number|null
Defined in: packages/client/src/errors.ts:28
Parsed Retry-After (seconds or HTTP-date) in milliseconds, or null when absent.
Returns
number | null
Inherited from
Methods
has()
has(
field):boolean
Defined in: packages/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: packages/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: packages/client/src/errors.ts:77
All field errors.
Returns
Record<string, string[]>
fields()
fields():
string[]
Defined in: packages/client/src/errors.ts:82
The names of every field that failed.
Returns
string[]