# Errors

Every API error is one JSON value:

```json
{"error":{"code":"payment_due","message":"...","retryable":false,"retryAfterSeconds":null}}
```

`code` is one of the codes below. `message` says what to do next, in words for a person. Retry only an error whose `retryable` is `true`, and wait `retryAfterSeconds` first when it is set. With `--json`, `thz` prints the same value on stdout. Without `--json`, it prints `thz: <code>: <message>` on stderr.

## Error codes

| Code | HTTP | Retry | `thz` exit code | Meaning |
|---|---|---|---|---|
| `invalid_request` | 400 | no | 1 | A field or value is wrong. |
| `missing_key` | 401 | no | 3 | The call has no key. |
| `invalid_key` | 401 | no | 3 | The key does not exist. |
| `expired_key` | 401 | no | 3 | The key has expired. |
| `revoked_key` | 401 | no | 3 | The owner revoked the key. |
| `missing_scope` | 403 | no | 3 | The key's preset does not allow this call. |
| `account_suspended` | 403 | no | 5 | The account is suspended, so machines cannot start. |
| `payment_due` | 403 | no | 5 | The plan has not started. The owner must pay first. |
| `not_found` | 404 | no | 4 | No such machine or key in this account. |
| `name_taken` | 409 | no | 1 | Another kept machine has this name. |
| `not_running` | 409 | no | 1 | The machine is not running. |
| `not_stopped` | 409 | no | 1 | The machine is not stopped. |
| `delete_confirmation_required` | 409 | no | 1 | A delete did not confirm the machine's name. `thz rm --yes` confirms it. |
| `disk_expired` | 410 | no | 1 | The machine stopped more than 14 days ago, and its disk is gone. |
| `start_limit_reached` | 429 | yes | 5 | Too many starts. `retryAfterSeconds` says when a start is free again. |
| `running_limit_reached` | 429 | no | 5 | The account already runs as many machines as its running limit, 100 on the $20 plan. |
| `machine_limit_reached` | 429 | no | 5 | The account already keeps as many machines as its kept limit, 200 on the $20 plan, running and stopped together. |
| `wallet_empty` | 402 | no | 5 | The wallet cannot pay for an extra start or the next minute. |
| `claim_refused` | 403 | no | 3 | The owner refused the claim. |
| `claim_expired` | 403 | no | 3 | The claim's code ran out, was used, or does not exist. |
| `no_ready_machine` | 503 | yes | 75 | No machine is ready now. Nothing was counted or charged. |
| `already_credited` | 409 | no | 1 | Operator commands only. |
| `invite_code_required` | 403 | no | 3 | A sign-up had no invite code, or one that does not exist. |
| `invite_code_used` | 409 | no | 3 | The invite code already made an account. |
| `too_many_attempts` | 429 | yes | 75 | Too many codes that match nothing were entered at `/device`. |

## Other exit codes

| Exit code | When |
|---|---|
| 0 | The command worked. |
| 1 | Any other error. |
| 2 | The command line was wrong. |
| 124 | `thz exec` or `thz run` ended the command at its timeout. |
| 130 | Ctrl-C interrupted the command. |

`thz exec` and `thz run` exit with the command's own exit code. Their `--json` output has an `error` field only when the service failed, so a command that exits 3 is not mistaken for `claim_refused`.
