Wildberries API TypeScript SDK / AuthenticationError
Class: AuthenticationError
Defined in: errors/auth-error.ts:25
Authentication error thrown when API key is invalid or lacks permissions.
This error is thrown for:
- 401 Unauthorized responses (invalid API key)
- 403 Forbidden responses (insufficient permissions)
- Client-side API key validation failures
Example
typescript
import { AuthenticationError } from 'daytona-wildberries-typescript-sdk';
try {
await sdk.general.ping();
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Invalid API key:', error.getUserMessage());
// Prompt user to update API key in settings
}
}Extends
Constructors
Constructor
ts
new AuthenticationError(
message: string,
statusCode: 401 | 403,
response?: unknown,
requestId?: string,
origin?: string,
timestamp?: string): AuthenticationError;Defined in: errors/auth-error.ts:36
Creates an authentication error
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
message | string | 'Authentication failed. Please verify your API key is valid and has the required permissions.' | Error message (defaults to standard authentication failure message) |
statusCode | 401 | 403 | 401 | HTTP status code (401 or 403) |
response? | unknown | undefined | API response body if available |
requestId? | string | undefined | Correlation ID for debugging |
origin? | string | undefined | Origin service identifier from RFC 7807 responses |
timestamp? | string | undefined | ISO 8601 timestamp from RFC 7807 responses |
Returns
AuthenticationError
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="origin"></a> origin? | readonly | string | Origin service identifier from RFC 7807 problem+json responses. Indicates which internal Wildberries service originated the error (e.g., "s2s-api-auth-catalog"). | WBAPIError.origin | errors/base-error.ts:43 |
<a id="timestamp"></a> timestamp? | readonly | string | ISO 8601 timestamp from RFC 7807 problem+json responses. Indicates when the error occurred on the server side (e.g., "2024-09-30T06:52:38Z"). | WBAPIError.timestamp | errors/base-error.ts:51 |
Methods
getUserMessage()
ts
getUserMessage(): string;Defined in: errors/auth-error.ts:53
Returns user-friendly error message with API key troubleshooting guidance
Returns
string
Error message with actionable recovery steps
Overrides
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
| Name | Type | Defined in |
|---|---|---|
name | string | errors/base-error.ts:157 |
message | string | errors/base-error.ts:158 |
statusCode? | number | errors/base-error.ts:159 |
response? | unknown | errors/base-error.ts:160 |
requestId? | string | errors/base-error.ts:161 |
origin? | string | errors/base-error.ts:162 |
timestamp? | string | errors/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, ... }