> For the complete documentation index, see [llms.txt](https://docs.blog-api.codewithsadee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blog-api.codewithsadee.com/guides/error-handling.md).

# Error Handling

The API uses standard HTTP status codes to indicate the success or failure of a request. Errors generally return a JSON body with `code` and `message` fields. Validation errors include an additional `errors` object.

## Common Status Codes & Error Codes

| Status Code                 | `code` Value(s)       | Meaning                                                                                                  |
| --------------------------- | --------------------- | -------------------------------------------------------------------------------------------------------- |
| `200 OK`                    | N/A                   | Request successful.                                                                                      |
| `201 Created`               | N/A                   | Resource created successfully.                                                                           |
| `204 No Content`            | N/A                   | Request successful, no response body needed (e.g., successful deletion).                                 |
| `400 Bad Request`           | `ValidationError`     | Input validation failed (e.g., missing required field, invalid format). See `errors` object for details. |
| `400 Bad Request`           | `BadRequest`          | General bad request (e.g., trying to like an already liked blog).                                        |
| `401 Unauthorized`          | `AuthenticationError` | Missing, invalid, or expired `accessToken` or `refreshToken`. Check `message` for specifics.             |
| `403 Forbidden`             | `AuthorizationError`  | User lacks permission (role) for the action, or attempting unauthorized admin registration.              |
| `404 Not Found`             | `NotFound`            | The requested resource (user, blog, comment) could not be found.                                         |
| `413 Payload Too Large`     | `ValidationError`     | Uploaded file exceeds the size limit (2MB for blog banners).                                             |
| `429 Too Many Requests`     | N/A                   | Rate limit exceeded (see Rate Limiting guide).                                                           |
| `500 Internal Server Error` | `ServerError`         | An unexpected error occurred on the server. Contact support if this persists.                            |

## Error Response Format

**General Error:**

```json
{
  "code": "NotFound",
  "message": "Blog not found"
}
```

**Validation Error:**

```json
{
  "code": "ValidationError",
  "errors": {
    "email": {
      "type": "field",
      "value": "invalid-email",
      "msg": "Invalid email address",
      "path": "email",
      "location": "body"
    },
    "password": {
      "type": "field",
      "value": "short",
      "msg": "Password must be at least 8 characters long",
      "path": "password",
      "location": "body"
    }
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.blog-api.codewithsadee.com/guides/error-handling.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
