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

# Error Handling

> Handle errors gracefully with NoCloudAPIError

The SDK provides detailed error handling through `NoCloudAPIError` and the `NoCloudError` enum.

## Basic Error Handling

```typescript theme={null}
import { NoCloud, NoCloudAPIError } from "@nocloud/sdk";

const cloud = new NoCloud("your-api-key");

try {
  await cloud.storage.upload(file);
} catch (error) {
  if (error instanceof NoCloudAPIError) {
    console.error(`API Error: ${error.message}`);
    console.error(`Status: ${error.status}`);
    console.error(`Code: ${error.code}`);
  }
}
```

## Check for Specific Errors

Use the static `isError` method to check for specific error types:

```typescript theme={null}
import { NoCloudAPIError, NoCloudError } from "@nocloud/sdk";

try {
  await cloud.storage.upload(file);
} catch (error) {
  if (NoCloudAPIError.isError(error, NoCloudError.RATE_LIMIT_EXCEEDED)) {
    console.log("Rate limited, retry later");
  } else if (NoCloudAPIError.isError(error, NoCloudError.INVALID_API_KEY)) {
    console.log("Check your API key");
  } else if (NoCloudAPIError.isError(error)) {
    console.log(`Other API error: ${error.code}`);
  }
}
```

## Error Codes

| Code                    | HTTP Status | Description                |
| ----------------------- | ----------- | -------------------------- |
| `INVALID_API_KEY`       | 401         | Invalid or missing API key |
| `BAD_REQUEST`           | 400         | Invalid request parameters |
| `RATE_LIMIT_EXCEEDED`   | 429         | Too many requests          |
| `RESOURCE_NOT_FOUND`    | 404         | File or resource not found |
| `INTERNAL_SERVER_ERROR` | 500         | Server error               |
| `UNKNOWN_ERROR`         | —           | Unexpected error           |

## NoCloudAPIError Properties

| Property  | Type           | Description                  |
| --------- | -------------- | ---------------------------- |
| `message` | `string`       | Human-readable error message |
| `status`  | `number`       | HTTP status code             |
| `code`    | `NoCloudError` | Error code enum value        |

## Retry Logic

The SDK includes built-in retry logic for transient failures. You can configure the retry behavior when initializing:

```typescript theme={null}
const cloud = new NoCloud({
  apiKey: "your-api-key",
  retries: 5, // Retry up to 5 times
  retryDelayMs: 2000 // Wait 2 seconds between retries
});
```

<Note>
  The SDK will automatically retry failed requests for transient errors (like
  network issues). It will not retry for client errors like invalid API keys or
  bad requests.
</Note>

## Handling Rate Limits

When you exceed the rate limit, the SDK throws a `RATE_LIMIT_EXCEEDED` error:

```typescript theme={null}
import { NoCloudAPIError, NoCloudError } from "@nocloud/sdk";

async function uploadWithRetry(file: File, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await cloud.storage.upload(file);
    } catch (error) {
      if (NoCloudAPIError.isError(error, NoCloudError.RATE_LIMIT_EXCEEDED)) {
        // Wait before retrying
        await new Promise((resolve) => setTimeout(resolve, 5000));
        continue;
      }
      throw error;
    }
  }
  throw new Error("Max retries exceeded");
}
```
