> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reducto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 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:

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

***

## Common Error Handling

```javascript theme={null}
import Reducto, { 
  APIError, 
  AuthenticationError, 
  BadRequestError,
  RateLimitError 
} from 'reductoai';

try {
  const result = await client.parse.run({ input: upload.file_id });
} 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

```javascript theme={null}
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 });
    } 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`:

```javascript theme={null}
// 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
});
```

***

## Next Steps

* Learn about [job management](/sdk/javascript/job-management) for async operations
* Explore the [JavaScript SDK overview](/sdk/javascript/overview) for usage patterns
