Skip to content

Wildberries API TypeScript SDK / WBAPIError

Class: WBAPIError

Defined in: errors/base-error.ts:21

Base error class for all Wildberries SDK errors.

All SDK-specific errors extend this class to enable consumers to catch all SDK errors with a single catch block if desired.

Example

typescript
import { WBAPIError } from 'daytona-wildberries-typescript-sdk';

try {
  await sdk.general.ping();
} catch (error) {
  if (error instanceof WBAPIError) {
    console.error('SDK error:', error.getUserMessage());
    console.error('Status code:', error.statusCode);
  }
}

Extends

  • Error

Extended by

Constructors

Constructor

ts
new WBAPIError(
   message: string, 
   statusCode?: number, 
   response?: unknown, 
   requestId?: string, 
   origin?: string, 
   timestamp?: string): WBAPIError;

Defined in: errors/base-error.ts:63

Creates a new WBAPIError

Parameters

ParameterTypeDescription
messagestringError message describing what went wrong
statusCode?numberHTTP status code if applicable
response?unknownAPI response body if available
requestId?stringCorrelation ID for debugging
origin?stringOrigin service identifier from RFC 7807 responses
timestamp?stringISO 8601 timestamp from RFC 7807 responses

Returns

WBAPIError

Overrides

ts
Error.constructor

Properties

PropertyModifierTypeDescriptionDefined in
<a id="statuscode"></a> statusCode?readonlynumberHTTP status code if applicableerrors/base-error.ts:25
<a id="response"></a> response?readonlyunknownAPI response body if availableerrors/base-error.ts:30
<a id="requestid"></a> requestId?readonlystringCorrelation ID for debugging and tracing requestserrors/base-error.ts:35
<a id="origin"></a> origin?readonlystringOrigin service identifier from RFC 7807 problem+json responses. Indicates which internal Wildberries service originated the error (e.g., "s2s-api-auth-catalog").errors/base-error.ts:43
<a id="timestamp"></a> timestamp?readonlystringISO 8601 timestamp from RFC 7807 problem+json responses. Indicates when the error occurred on the server side (e.g., "2024-09-30T06:52:38Z").errors/base-error.ts:51

Methods

getUserMessage()

ts
getUserMessage(): string;

Defined in: errors/base-error.ts:122

Returns a human-readable error message with recovery guidance.

Override this method in subclasses to provide specific recovery steps.

Returns

string

User-friendly error message with actionable guidance

Example

typescript
try {
  await sdk.products.createProduct(data);
} catch (error) {
  if (error instanceof WBAPIError) {
    // Show user-friendly message
    alert(error.getUserMessage());

    // Log technical details for debugging
    console.error('Technical details:', {
      statusCode: error.statusCode,
      requestId: error.requestId
    });
  }
}

toJSON()

ts
toJSON(): {
  name: string;
  message: string;
  statusCode?: number;
  response?: unknown;
  requestId?: string;
  origin?: string;
  timestamp?: string;
};

Defined in: errors/base-error.ts:156

Custom JSON serialization to preserve all error properties.

By default, Error objects don't serialize the message property when using JSON.stringify(). This method ensures all important properties are included in the JSON output.

Returns

ts
{
  name: string;
  message: string;
  statusCode?: number;
  response?: unknown;
  requestId?: string;
  origin?: string;
  timestamp?: string;
}

Object representation of the error for JSON serialization

NameTypeDefined in
namestringerrors/base-error.ts:157
messagestringerrors/base-error.ts:158
statusCode?numbererrors/base-error.ts:159
response?unknownerrors/base-error.ts:160
requestId?stringerrors/base-error.ts:161
origin?stringerrors/base-error.ts:162
timestamp?stringerrors/base-error.ts:163

Example

typescript
const error = new WBAPIError('Test error', 400, { detail: 'info' }, 'req-123');
const json = JSON.stringify(error);
// { "name": "WBAPIError", "message": "Test error", "statusCode": 400, ... }

Made with ❤️ for the Wildberries developer community