> For the complete documentation index, see [llms.txt](https://cde-inc.gitbook.io/cde-cad-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cde-inc.gitbook.io/cde-cad-documentation/rest-api/error-handling.md). Agents can also search and read this documentation through its [MCP server](https://cde-inc.gitbook.io/cde-cad-documentation/~gitbook/mcp).

# Error Handling

The API uses standard HTTP status codes and returns consistent JSON error responses.

***

## Error Response Format

```
{
  "error": "Short error code",
  "message": "Human-readable description of what went wrong",
  "statusCode": 400
}
```

**Example - Unauthorized request:**

```
HTTP/1.1 401 Unauthorized
Content-Type: application/json

{
  "error": "UNAUTHORIZED",
  "message": "Invalid or expired authentication token",
  "statusCode": 401
}
```

**Example - Validation error:**

```
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "error": "VALIDATION_ERROR",
  "message": "Missing required field: firstName",
  "statusCode": 400
}
```

**HTTP Status Codes**

|          |                       |                                                 |
| -------- | --------------------- | ----------------------------------------------- |
| **Code** | **Status**            | **Description**                                 |
| 200      | OK                    | Request succeeded                               |
| 201      | Created               | Resource created successfully                   |
| 400      | Bad Request           | Invalid request body or missing required fields |
| 401      | Unauthorized          | Missing or invalid authentication credentials   |
| 403      | Forbidden             | Authenticated but insufficient permissions      |
| 404      | Not Found             | Requested resource does not exist               |
| 429      | Too Many Requests     | Rate limit exceeded; wait and retry             |
| 500      | Internal Server Error | Unexpected server error; contact support        |

## License Application Codes

The FiveM DMV route, `POST /api/fivem/dmv/license`, refuses with `success: false`, a `msg` you can show to the player, and one of these codes. The full list, with the DMV's own codes, is on [DMV Driving Licenses](https://cde-inc.gitbook.io/cde-cad-documentation/fivem-developer-integration/dmv-licenses.md#refusals).

| Status | `code`                        | When                                                                                                                                                                                 |
| ------ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `400`  | `LICENSE_TYPE_DISABLED`       | The community has turned this built-in license type off under **Community Admin > Civilian > Custom licenses and exams > Built-in licenses**. Licenses already issued are unaffected |
| `400`  | `LICENSE_CLASS_UNKNOWN`       | `licenseClass` is not one of the community's class ids, or is a class for another license type                                                                                       |
| `400`  | `LICENSE_ENDORSEMENT_UNKNOWN` | An endorsement id is not in the community's list, or is set for another license type                                                                                                 |
| `409`  | `DMV_LICENSE_HELD`            | The license is suspended or revoked, or already valid                                                                                                                                |

## Rate Limit Response

When rate limited, the response includes a `Retry-After` header:

```
HTTP/1.1 429 Too Many Requests
Retry-After: &lt;seconds&gt;
Content-Type: application/json

{
  "error": "RATE_LIMIT_EXCEEDED",
  "message": "Too many requests. Please wait before retrying.",
  "statusCode": 429
}
```

## Cloudflare x-payload Workaround

{% hint style="warning" %}
**FiveM Body Stripping Issue**

FiveM's HTTP client may strip the request body on certain request types when routed through Cloudflare. If you experience empty body errors from FiveM, use the `x-payload` header as a workaround:

```
-- Lua example (FiveM)
PerformHttpRequest("https://cdecad.com/api/fivem/911", function(code, text)
    -- handle response
end, "POST", "", {
    ["Content-Type"] = "application/json",
    ["x-api-key"] = "fvm_abc123def456",
    ["x-payload"] = json.encode({
        callerName = "John Doe",
        location = "Legion Square",
        description = "Shots fired"
    })
})
```

The server will parse `x-payload` as the request body when the actual body is empty or missing.
{% endhint %}

{% hint style="info" %}
**Need Help?**

If you encounter persistent errors or unexpected behavior, please open a support ticket in our Discord server with:

* The full request URL and method
* Request headers (redact tokens/keys)
* Request body (if applicable)
* The full error response
  {% endhint %}
