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
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
AuthenticationErrorRateLimitErrorValidationErrorNetworkErrorCampaignNotFoundErrorBudgetExceededErrorInvalidCampaignStateErrorPickupOrderNotFoundErrorInvalidOrderStateErrorCustomerVerificationErrorMetadataValidationError
Constructors
Constructor
new WBAPIError(
message: string,
statusCode?: number,
response?: unknown,
requestId?: string): WBAPIError;Defined in: errors/base-error.ts:45
Creates a new WBAPIError
Parameters
| Parameter | Type | Description |
|---|---|---|
message | string | Error message describing what went wrong |
statusCode? | number | HTTP status code if applicable |
response? | unknown | API response body if available |
requestId? | string | Correlation ID for debugging |
Returns
WBAPIError
Overrides
Error.constructorProperties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
<a id="statuscode"></a> statusCode? | readonly | number | HTTP status code if applicable | errors/base-error.ts:25 |
<a id="response"></a> response? | readonly | unknown | API response body if available | errors/base-error.ts:30 |
<a id="requestid"></a> requestId? | readonly | string | Correlation ID for debugging and tracing requests | errors/base-error.ts:35 |
Methods
getUserMessage()
getUserMessage(): string;Defined in: errors/base-error.ts:95
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
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()
toJSON(): {
name: string;
message: string;
statusCode?: number;
response?: unknown;
requestId?: string;
};Defined in: errors/base-error.ts:125
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
{
name: string;
message: string;
statusCode?: number;
response?: unknown;
requestId?: string;
}Object representation of the error for JSON serialization
| Name | Type | Defined in |
|---|---|---|
name | string | errors/base-error.ts:126 |
message | string | errors/base-error.ts:127 |
statusCode? | number | errors/base-error.ts:128 |
response? | unknown | errors/base-error.ts:129 |
requestId? | string | errors/base-error.ts:130 |
Example
const error = new WBAPIError('Test error', 400, { detail: 'info' }, 'req-123');
const json = JSON.stringify(error);
// { "name": "WBAPIError", "message": "Test error", "statusCode": 400, ... }