# Errors

## Success

Every success is HTTP 200 in the v1 envelope. Operations with no payload leave out `data`.

```json
{ "success": true, "code": 200, "data": { "usuario": { "id": 1042 } } }
```

## Business errors

A business error keeps the envelope, with HTTP 409 and the reason in `msg`, in Portuguese:

```json
{ "success": false, "code": 409, "msg": "Usuário não encontrado" }
```

Each operation in the [reference](https://cademi.dev/api/v1/reference.md) lists its messages. Compare `success` and the HTTP status; treat `msg` as text for people.

## Other errors

Authentication, routing and validation errors use a shorter body, with the text in `message` (not `msg`). The text starts with a space.

| HTTP | When |
|---|---|
| 401 | `Authorization` missing, or the key does not exist or was deleted |
| 404 | No route matches, for example a non-numeric ID where a number is expected |
| 405 | Wrong HTTP method for the path |
| 409 | Validation failed: `message` lists every problem, separated by commas |

```json
{ "code": 409, "success": false, "message": " O campo \"tag id\" é obrigatório" }
```
