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

# Error Codes

> REST API error codes and troubleshooting guide.

## Error Code Reference

| Code   | Constant                     | Message        | Description               |
| ------ | ---------------------------- | -------------- | ------------------------- |
| `0`    | OK                           | OK             | Success                   |
| `4000` | ERROR\_CODE\_INVALID\_UNIT   | Invalid unit   | Invalid ad unit ID        |
| `4001` | ERROR\_CODE\_AD\_INACTIVE    | Ad inactive    | No active ad campaigns    |
| `4002` | ERROR\_CODE\_AD\_NO\_FILL    | No fill        | No matching ads available |
| `4003` | ERROR\_CODE\_INVALID\_PARAMS | Invalid params | Invalid parameters        |

***

## Detailed Error Descriptions

### ERROR\_CODE\_INVALID\_UNIT (4000)

**Cause**: Requested with a non-existent or deactivated ad unit ID.

**Solutions**:

* Verify the ad unit ID is correct in the console
* Check that the ad unit is in active status
* Ensure no whitespace or special characters were included when copying

```json theme={null}
{
    "code": 4000,
    "msg": "Invalid unit",
    "result": null
}
```

***

### ERROR\_CODE\_AD\_INACTIVE (4001)

**Cause**: No active ad campaigns for the specified ad unit.

**Solutions**:

* Verify campaigns are running in the console
* Check campaign schedule (start/end dates)
* Ensure campaign budget is not exhausted

```json theme={null}
{
    "code": 4001,
    "msg": "Ad inactive",
    "result": null
}
```

***

### ERROR\_CODE\_AD\_NO\_FILL (4002)

**Cause**: Unable to find ads matching the targeting criteria.

**Solutions**:

* Check if targeting settings are too restrictive
* Implement retry logic (exponential backoff recommended)
* Prepare fallback content

```json theme={null}
{
    "code": 4002,
    "msg": "No fill",
    "result": null
}
```

**Retry Implementation Example**:

```javascript theme={null}
async function requestAdWithRetry(params, maxRetries = 3) {
    for (let i = 0; i < maxRetries; i++) {
        try {
            const response = await axios.get('https://api-v2.adrop.io/request', {
                params,
                headers: { 'Authorization': 'YOUR_APP_KEY' }
            });

            if (response.data.code === 0) {
                return response.data.result;
            }

            if (response.data.code === 4002) {
                // No fill - retry
                await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
                continue;
            }

            // Return immediately for other errors
            throw new Error(response.data.msg);
        } catch (error) {
            if (i === maxRetries - 1) throw error;
        }
    }

    return null; // Show fallback content
}
```

***

### ERROR\_CODE\_INVALID\_PARAMS (4003)

**Cause**: Request parameters are malformed.

**Solutions**:

* Verify required parameter (`unit`) is included
* Check that parameter values are in correct format
* Ensure no typos in parameter names

```json theme={null}
{
    "code": 4003,
    "msg": "Invalid params",
    "result": null
}
```

**Parameter Checklist**:

| Parameter | Required    | Valid Examples          |
| --------- | ----------- | ----------------------- |
| `unit`    | Required    | `AD_UNIT_123`           |
| `pf`      | Recommended | `android`, `ios`, `web` |
| `lcl`     | Recommended | `ko_KR`, `en_US`        |
| `theme`   | Optional    | `light`, `dark`         |

***

## Error Handling Best Practices

### 1. Handle Errors Based on Code

```javascript theme={null}
function handleAdResponse(response) {
    switch (response.code) {
        case 0:
            // Success - render ad
            renderAd(response.result);
            break;
        case 4000:
            // Unit ID error - log it
            console.error('Invalid unit ID');
            break;
        case 4001:
        case 4002:
            // No ads - show fallback content
            showFallbackContent();
            break;
        case 4003:
            // Parameter error - alert developers
            console.error('Invalid parameters:', response.msg);
            break;
        default:
            // Unknown error
            console.error('Unknown error:', response.code, response.msg);
    }
}
```

### 2. Prepare Fallback Content

```javascript theme={null}
function showFallbackContent() {
    const container = document.getElementById('ad-container');
    container.innerHTML = `
        <div class="fallback-content">
            <img src="/images/house-ad.jpg" alt="House Ad" />
        </div>
    `;
}
```

### 3. Monitoring and Logging

```javascript theme={null}
function logAdError(code, message, params) {
    // Monitor error rates
    analytics.track('ad_error', {
        error_code: code,
        error_message: message,
        unit_id: params.unit,
        timestamp: new Date().toISOString()
    });
}
```

***

## HTTP Status Codes

The REST API also returns standard HTTP status codes.

| HTTP Status | Description                                             |
| ----------- | ------------------------------------------------------- |
| `200`       | Request successful (check response body for error code) |
| `401`       | Authentication failed (verify App Key)                  |
| `500`       | Internal server error                                   |

<Warning>
  Always check the `code` value in the response body even for HTTP 200. Business logic errors are included in the response body.
</Warning>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="REST API Overview" icon="server" href="/sdk/rest-api">
    Basic API usage
  </Card>

  <Card title="Targeting Settings" icon="bullseye" href="/sdk/rest-api/targeting">
    Configure targeting parameters
  </Card>
</CardGroup>
