RFC 7807 Problem Details¶
This API uses RFC 7807 Problem Details for standardized error responses.
Response Format¶
All error responses return a JSON object with these fields:
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | URL to the documentation for this error type |
title | string | Yes | Short, human-readable summary |
status | integer | Yes | HTTP status code |
detail | string | Yes | Specific explanation of this occurrence |
instance | string | No | URI of the specific request that caused the error |
Example Response¶
{
"type": "https://github.com/open-ev-data/open-ev-data-api/blob/main/docs/API_ERRORS.md#errorsnot-found",
"title": "Resource Not Found",
"status": 404,
"detail": "Vehicle not found with code: tesla:model_x:2099:model_x",
"instance": "/api/v1/vehicles/code/tesla:model_x:2099:model_x"
}
Implementation¶
Adding New Error Types¶
- Define the error variant in
error.rs:
- Map it in
to_problem_details():
Self::NewError(detail) => (
StatusCode::UNPROCESSABLE_ENTITY,
ProblemDetails::new(
"https://github.com/open-ev-data/open-ev-data-api/blob/main/docs/API_ERRORS.md#errorsnew-error",
"New Error Title",
StatusCode::UNPROCESSABLE_ENTITY,
detail.clone(),
),
),
- Document in API_ERRORS.md with matching anchor ID.