# Responses and errors

> JSON responses come in the same envelope. On success you get data, on error you get error, with a code and an HTTP status.

JSON responses come in the same envelope. There are two exceptions: `/openapi.json` returns the description itself, without an envelope, and the PDF endpoints return the raw PDF when called with the `Accept: application/pdf` header.

## Success

```json
{ "success": true, "data": { } }
```

## Error

```json
{
  "success": false,
  "error": { "code": "SZAMLAZZ_3", "message": "Sikertelen bejelentkezés.", "httpStatus": 422, "details": {} }
}
```

| Field | Meaning |
|---|---|
| `code` | The error code. Business errors from számlázz.hu come as `SZAMLAZZ_<code>`. |
| `message` | A readable description. |
| `httpStatus` | The HTTP status. Business errors from számlázz.hu come with `422`. |
| `details` | Additional data, for example the invalid fields. |

For an invalid request (the body or the query does not match the description) the code is `VALIDATION_ERROR`, and the status is also `422`.

## Error codes

| Code | Status | Meaning |
|---|---|---|
| `MISSING_AGENT_KEY` | `401` | No Agent key was sent. |
| `VALIDATION_ERROR` | `422` | The request does not match the description. |
| `SZAMLAZZ_<code>` | `422` | számlázz.hu reported a business error. `<code>` is the számlázz.hu numeric code. |
| `SZAMLAZZ_SDK_ERROR` | `502` | A transport error occurred while reaching számlázz.hu, and it is not a business error. |
| `NOT_FOUND` | `404` | Unknown route. |
| `METHOD_NOT_ALLOWED` | `405` | The route does not support the method. |
| `INTERNAL_ERROR` | `500` | Any other server-side error. |
