Skip to content

Retries and Timeouts

The SDK includes built-in retry logic with exponential backoff and full jitter. All retry and timeout behavior is configurable.

  • Retries: 3 attempts
  • Backoff: Exponential with full jitter
  • Retry status codes: [408, 429, 500, 502, 503, 504]

Set retry and timeout options when creating the client.

const client = new BigshipClient({
baseURL: 'https://api.bigship.in',
userName: 'your-email@example.com',
password: 'your-password',
accessKey: 'your-access-key',
// Retry configuration
maxRetries: 3, // Max retry attempts (default: 3)
retryDelay: 1000, // Base retry delay in ms (default: 1000)
maxRetryDelay: 30000, // Max retry delay cap in ms (default: 30000)
retryOnStatusCodes: [408, 429, 500, 502, 503, 504], // Status codes to retry on
// Global timeout
timeout: 15000, // Request timeout in ms (default: 15000)
});

Override the timeout for a single call.

await client.addSingleOrder(order, { timeout: 60000 });

Cancel in-flight requests using AbortController.

const controller = new AbortController();
// Start the request
const balancePromise = client.getWalletBalance({ signal: controller.signal });
// Cancel after 5 seconds
setTimeout(() => controller.abort(), 5000);
try {
const balance = await balancePromise;
} catch (error) {
// Request was aborted
}
Code Description
408 Request Timeout
429 Too Many Requests
500 Internal Server Error
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
const client = new BigshipClient({
// ...
maxRetries: 0,
});
const client = new BigshipClient({
// ...
retryOnStatusCodes: [408, 429, 500, 502, 503, 504, 409],
});
const client = new BigshipClient({
// ...
retryDelay: 2000, // 2 second base delay
maxRetryDelay: 60000, // 1 minute max delay
});

Use the onRetry hook to log or monitor retry attempts.

const client = new BigshipClient({
// ...
onRetry: (attempt, error, ctx) => {
console.warn(`Retry attempt ${attempt} for ${ctx.endpoint}: ${error.message}`);
},
});