Wildberries API TypeScript SDK / ValidationError
Class: ValidationError
Defined in: errors/validation-error.ts:35
Validation error thrown when request data fails validation.
This error is thrown for:
- 400 Bad Request responses (malformed requests)
- 422 Unprocessable Entity responses (validation failures)
Includes field-level error details when available to help identify which specific fields failed validation.
Example
typescript
import { ValidationError } from 'daytona-wildberries-typescript-sdk';
try {
await sdk.products.createProduct({
// Missing required fields
});
} catch (error) {
if (error instanceof ValidationError) {
console.error('Validation failed:', error.getUserMessage());
// Access field-level errors
if (error.fieldErrors) {
Object.entries(error.fieldErrors).forEach(([field, message]) => {
console.error(` - ${field}: ${message}`);
});
}
}
}Extends
Extended by
Constructors
Constructor
ts
new ValidationError(
message: string,
fieldErrors?: Record<string, string>,
statusCode?: 400 | 422,
response?: unknown,
requestId?: string): ValidationError;Defined in: errors/validation-error.ts:50
Creates a validation error
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
message | string | 'Validation failed. Please check the request data and try again.' | Error message (defaults to standard validation failure message) |
fieldErrors? | Record<string, string> | undefined | Optional map of field names to error messages |
statusCode? | 400 | 422 | 400 | HTTP status code (400 or 422) |
response? | unknown | undefined | API response body if available |
requestId? | string | undefined | Correlation ID for debugging |
Returns
ValidationError
Overrides
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
<a id="statuscode"></a> statusCode? | readonly | number | HTTP status code if applicable | WBAPIError.statusCode | errors/base-error.ts:25 |
<a id="response"></a> response? | readonly | unknown | API response body if available | WBAPIError.response | errors/base-error.ts:30 |
<a id="requestid"></a> requestId? | readonly | string | Correlation ID for debugging and tracing requests | WBAPIError.requestId | errors/base-error.ts:35 |
<a id="fielderrors"></a> fieldErrors? | readonly | Record<string, string> | Map of field names to their validation error messages | - | errors/validation-error.ts:39 |
Methods
getUserMessage()
ts
getUserMessage(): string;Defined in: errors/validation-error.ts:67
Returns user-friendly error message with field-level validation details
Returns
string
Error message with specific field errors and resolution guidance
Overrides
toJSON()
ts
toJSON(): {
name: string;
message: string;
statusCode: number;
fieldErrors?: Record<string, string>;
response?: unknown;
requestId?: string;
};Defined in: errors/validation-error.ts:100
Custom JSON serialization to preserve fieldErrors property
Returns
ts
{
name: string;
message: string;
statusCode: number;
fieldErrors?: Record<string, string>;
response?: unknown;
requestId?: string;
}Object representation including field-level error details
| Name | Type | Defined in |
|---|---|---|
name | string | errors/validation-error.ts:101 |
message | string | errors/validation-error.ts:102 |
statusCode | number | errors/validation-error.ts:103 |
fieldErrors? | Record<string, string> | errors/validation-error.ts:104 |
response? | unknown | errors/validation-error.ts:105 |
requestId? | string | errors/validation-error.ts:106 |