Skip to content

Wildberries API TypeScript SDK / InvalidOrderStateError

Class: InvalidOrderStateError

Defined in: errors/in-store-pickup-errors.ts:98

Error thrown when an order state transition is invalid

HTTP Status: 409 Conflict Retry: No (permanent failure - requires state correction) Rate Limit: 409 responses count as 10 requests!

This error occurs when attempting to transition an order to a state that is not valid given its current state (e.g., trying to prepare an order that hasn't been confirmed yet).

Valid State Transitions:

  • newconfirm (confirmOrder)
  • confirmprepare (prepareOrder)
  • preparereceive (receiveOrder) - terminal state
  • preparereject (rejectOrder) - terminal state
  • Any → cancel (cancelOrder) - terminal state

Example

typescript
try {
  // Trying to prepare order without confirming first
  await sdk.inStorePickup.prepareOrder(12345);
} catch (error) {
  if (error instanceof InvalidOrderStateError) {
    console.error(`Cannot ${error.attemptedAction} order ${error.orderId}`);
    console.error(`Current state: ${error.currentState}`);
    console.error('Recovery:', error.getUserMessage());

    // Get current status and retry with correct action
    const statuses = await sdk.inStorePickup.getOrderStatuses([error.orderId]);
    const currentState = statuses.orders[0]?.supplierStatus;
    // Handle based on current state
  }
}

Extends

Constructors

Constructor

ts
new InvalidOrderStateError(
   orderId: number, 
   currentState: string | undefined, 
   attemptedAction: string, 
   requestId?: string): InvalidOrderStateError;

Defined in: errors/in-store-pickup-errors.ts:107

Creates a new InvalidOrderStateError

Parameters

ParameterTypeDescription
orderIdnumberID of the order with invalid state
currentStatestring | undefinedCurrent state of the order (if known)
attemptedActionstringAction that was attempted (e.g., "prepare", "receive")
requestId?stringOptional request ID from API response

Returns

InvalidOrderStateError

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="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").WBAPIError.originerrors/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").WBAPIError.timestamperrors/base-error.ts:51
<a id="orderid"></a> orderIdreadonlynumberID of the order with invalid state-errors/in-store-pickup-errors.ts:108
<a id="currentstate"></a> currentStatereadonlystring | undefinedCurrent state of the order (if known)-errors/in-store-pickup-errors.ts:109
<a id="attemptedaction"></a> attemptedActionreadonlystringAction that was attempted (e.g., "prepare", "receive")-errors/in-store-pickup-errors.ts:110

Methods

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, ... }

Inherited from

WBAPIError.toJSON


getUserMessage()

ts
getUserMessage(): string;

Defined in: errors/in-store-pickup-errors.ts:131

Returns user-friendly error message with recovery guidance

Returns

string

Overrides

WBAPIError.getUserMessage

Made with ❤️ for the Wildberries developer community