Skip to content

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

ParameterTypeDefault valueDescription
messagestring'Validation failed. Please check the request data and try again.'Error message (defaults to standard validation failure message)
fieldErrors?Record<string, string>undefinedOptional map of field names to error messages
statusCode?400 | 422400HTTP status code (400 or 422)
response?unknownundefinedAPI response body if available
requestId?stringundefinedCorrelation ID for debugging

Returns

ValidationError

Overrides

WBAPIError.constructor

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
<a id="statuscode"></a> statusCode?readonlynumberHTTP status code if applicableWBAPIError.statusCodeerrors/base-error.ts:25
<a id="response"></a> response?readonlyunknownAPI response body if availableWBAPIError.responseerrors/base-error.ts:30
<a id="requestid"></a> requestId?readonlystringCorrelation ID for debugging and tracing requestsWBAPIError.requestIderrors/base-error.ts:35
<a id="fielderrors"></a> fieldErrors?readonlyRecord<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

WBAPIError.getUserMessage


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

NameTypeDefined in
namestringerrors/validation-error.ts:101
messagestringerrors/validation-error.ts:102
statusCodenumbererrors/validation-error.ts:103
fieldErrors?Record<string, string>errors/validation-error.ts:104
response?unknownerrors/validation-error.ts:105
requestId?stringerrors/validation-error.ts:106

Overrides

WBAPIError.toJSON

Made with ❤️ for the Wildberries developer community