# Errors

Every error from the API is JSON with two fields:

```json
{ "error": "filter_required", "message": "Say which rows to change, for example ?id=eq.<id>." }
```

`error` is a stable code for your program. `message` is words for a person, and may be reworded. Errors never carry stack traces, database messages or your data.

## By status

| Status | Meaning |
|---|---|
| 400 | The request is malformed, or the database refused a value |
| 401 | No valid key, token or code |
| 402 | The company's plan has no room left this month for what was asked. Nothing was deleted. See [Plans and limits](https://rezincore.com/docs/plans-and-limits.md). |
| 403 | Understood, and not allowed |
| 404 | No such table, file, project or organization, or one you may not know exists |
| 408 | The request took too long |
| 409 | It conflicts with what is already there |
| 429 | Too many requests. Wait a minute. |
| 500 | Something went wrong on our side |
| 502, 504 | One of your functions was stopped, crashed, or ran out of time |
| 503 | A part this request needs is not set up |

## Every code

### Keys and callers

| Code | Status | Meaning |
|---|---|---|
| `bad_key` | 401 | No valid project key in the `apikey` header |
| `sign_in_required` | 401 | A publishable key with no user's token |
| `signed_out` | 401 | The token has ended. Sign in again. |
| `organization_required` | 400 | A secret key with no token must name the organization in `x-organization-id` |
| `password_change_required` | 403 | This account must choose a new password first |
| `too_many_requests` | 429 | The key, the network address, or sign-in attempts hit a limit |

### Plans

| Code | Status | Meaning |
|---|---|---|
| `limit_reached` | 402 | The company has used all its plan includes of one thing this month (the message says which). Only that thing is refused; nothing was deleted. |
| `slowed` | 429 | The company reached its spending cap and chose to slow down rather than stop: this function ran less than ten seconds ago. Try again shortly. See [Spending caps and alerts](https://rezincore.com/docs/spending-caps.md). |
| `project_paused` | 403 | A Free project that was not used for 7 days. Its data is kept. Resume it in the console. |

### Sign-in

| Code | Status | Meaning |
|---|---|---|
| `bad_login` | 401 | Wrong email or password, or the account cannot sign in. It never says which. |
| `code_required` | 401 | The account uses an authenticator app. Send the same request again with the code. |
| `bad_second_step` | 401 | The authenticator code is not right |
| `bad_code` | 401 | A link or one-time code that has expired, was already used, or is not right |
| `bad_state` | 400 | A provider sign-in that has expired or was already used. Start again. |
| `weak_password` | 400 | Shorter than 12 characters, or longer than 200 |
| `email_in_use` | 409 | That email already has an account |
| `signup_closed` | 403 | The project does not let people create their own accounts |
| `method_off` | 403 | The project does not use that way of signing in |
| `confirm_first` | 403 | Send the current password, or confirm it is you first |
| `redirect_not_allowed`, `bad_redirect` | 400 | That return address is not on the project's list |
| `site_url_required` | 409 | The project has no Site URL to send people back to |
| `not_configured` | 503 | That sign-in provider is not set up |
| `email_not_ready` | 503 | Email is not set up for the project |

### Data

| Code | Status | Meaning |
|---|---|---|
| `bad_request` | 400 | An unknown column, a malformed filter, a wrong type or format, a missing required value, a value a constraint refuses |
| `filter_required` | 400 | `PATCH` and `DELETE` need a filter |
| `not_allowed` | 403 | The application may not do that to this table, or the row is outside what this account may write |
| `not_found` | 404 | No such table |
| `conflict` | 409 | A row with that value already exists, or it refers to a row that does not exist. The constraint is named. |
| `timeout` | 408 | The request took too long |

### Storage

| Code | Status | Meaning |
|---|---|---|
| `not_accepted` | 400 | The bucket's settings refuse this file |
| `server_only` | 403 | Only your own server may add or remove files in this bucket |
| `bad_link` | 403 | A signed link that has expired or is not valid |
| `not_found` | 404 | No such file |

### Functions

| Code | Status | Meaning |
|---|---|---|
| `not_found` | 404 | No such function in this project, or it is switched off |
| `sign_in_required` | 401 | The function takes signed-in users only |
| `busy` | 429 | Too many of the project's functions are running at once |
| `function_error` | 500 | The code threw. The error is in the function's log. |
| `function_memory` | 502 | Stopped for using too much memory |
| `function_output` | 502 | Stopped for printing or returning too much |
| `function_crashed` | 502 | Ended without answering |
| `function_timeout` | 504 | Stopped at its time limit |

### Tools (personal access tokens)

| Code | Status | Meaning |
|---|---|---|
| `bad_token` | 401 | Missing, wrong, revoked or expired token |
| `read_only` | 403 | The token is look-only, or your role is read-only |
| `network_not_allowed` | 403 | The project accepts its keys and tokens only from listed network addresses, and yours is not one. See [Database settings](https://rezincore.com/docs/database/settings.md#allowed-network-addresses) |
| `not_permitted` | 403 | The token or connection was not given the part of Rezin Core this belongs to |
| `deploy_not_permitted` | 403 | Deploying, changing or deleting a function needs the separate deploy permission |
| `sql_error` | 400 | The database refused the statement |
| `no_organization` | 409 | The project has no organization yet |
| `sql_not_ready` | 503 | The project's SQL role is not available |

### Everything else

| Code | Status | Meaning |
|---|---|---|
| `server_error` | 500 | Something went wrong on our side. Nothing about the cause is in the answer. |
| `method_not_allowed` | 405 | `GET /mcp`; the connector takes `POST` |

## Handling them well

- On `401 signed_out`, send the person to sign in again. There is no refresh token.
- On `401 code_required`, ask for the code and send the same request again. Nothing was used up.
- On `429`, wait a minute before trying again. Do not retry in a tight loop.
- On `403 not_allowed` for a table you just made: it has no policy yet, or the application has not been allowed to use it. See [Row-level security and policies](https://rezincore.com/docs/database/row-level-security.md).
- An empty `rows` list is not an error. It usually means the caller's policies let nothing through.
