Skip to content
Log in

Error Handling

Handle errors and exceptions in the Reducto JavaScript SDK

The Reducto JavaScript SDK throws specific error classes for different error conditions.


Error Classes

All error classes are exported from the main reductoai module:

import Reducto, {
  ReductoError,
  APIError,
  APIConnectionError,
  APIConnectionTimeoutError,
  APIUserAbortError,
  BadRequestError,
  AuthenticationError,
  PermissionDeniedError,
  NotFoundError,
  ConflictError,
  UnprocessableEntityError,
  RateLimitError,
  InternalServerError
} from 'reductoai';

Common Error Handling

import Reducto, { 
  APIError, 
  AuthenticationError, 
  BadRequestError,
  RateLimitError 
} from 'reductoai';

try {
  const result = await client.parse.run({ input: upload.file_id, settings: { model: "r-1" } });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error(`Auth failed: ${error.status} - ${error.message}`);
  } else if (error instanceof BadRequestError) {
    console.error(`Invalid request: ${error.status} - ${error.message}`);
  } else if (error instanceof RateLimitError) {
    console.error(`Rate limited: ${error.status} - ${error.message}`);
  } else if (error instanceof APIError) {
    console.error(`API error: ${error.status} - ${error.message}`);
  }
}

Retry Logic

import Reducto, { RateLimitError, InternalServerError, APIConnectionError } from 'reductoai';

async function parseWithRetry(client, upload, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      return await client.parse.run({ input: upload.file_id, settings: { model: "r-1" } });
    } catch (error) {
      // The SDK automatically retries connection errors and 5xx errors
      // You only need manual retry logic for specific cases
      if (error instanceof RateLimitError || error instanceof InternalServerError || error instanceof APIConnectionError) {
        if (attempt === maxRetries - 1) throw error;
        const waitTime = Math.pow(2, attempt); // Exponential backoff
        console.log(`Retrying in ${waitTime} seconds...`);
        await new Promise(resolve => setTimeout(resolve, waitTime * 1000));
      } else {
        throw error;
      }
    }
  }
}

Automatic Retries

The SDK automatically retries requests on:

  • Connection errors (APIConnectionError)
  • Request timeouts (APIConnectionTimeoutError)
  • 408 Request Timeout
  • 409 Conflict
  • 429 Rate Limit
  • 5xx Internal Server Errors

Default retry count is 2, configurable via maxRetries:

// Configure default retries for all requests
const client = new Reducto({
  maxRetries: 5  // default is 2
});

// Or per-request
await client.parse.run({ input: upload.file_id }, {
  maxRetries: 3,
  settings: { model: "r-1" },
});

Next Steps

Type to search…

escClose