# Errors

How errors are shaped, what each status means, and which requests to retry.

A route that refuses or fails answers with a 4xx or 5xx status and a JSON body. `message` says what is wrong, and some errors have more fields. [Every error](https://chatwise.so/docs/api/all-errors.md) lists them all.

An address that isn't a public route can answer 404 with HTML, or 401 with the message `Unauthorized`. If you get one of those, check the path and the method.

## Shapes

**Most errors** have only a message. Some 500s also have an `errorId`: quote it when you contact support.

```json
{
  "message": "Conversation not found"
}
```

**Invalid parameters and fields.** `errors` has one entry for each problem. `path` starts with `params`, `query`, `headers` or `body`.

```json
{
  "message": "Validation failed",
  "errors": [
    {
      "path": "query.limit",
      "message": "Limit must be an integer between 1 and 100"
    }
  ]
}
```

**A value that was refused.** `field` names it, and some have more in `data`.

```json
{
  "object": "Webhook endpoint",
  "field": "url",
  "message": "Use a public https:// URL on port 443, without a username, password or #fragment."
}
```

**Errors with a code.** Check `code` in your program, not `message`.

```json
{
  "code": "TEMPLATE_EXISTS",
  "message": "A WhatsApp template with this name and language already exists"
}
```

## Codes

| Code | Status | What it means |
| --- | --- | --- |
| `ADMIN_SERVICES_BLOCKED` | 402 | Sending is paused for the workspace. Contact support. |
| `WHATSAPP_REAUTH_REQUIRED` | 403 | Meta no longer accepts Chatwise's access to the number. `reason` is `expired`, `revoked` or `missing`. Reconnect it in the dashboard. |
| `TEMPLATE_EXISTS` | 409 | There is a template with this name and language. |
| `IDEMPOTENCY_KEY_REUSED` | 409 | The key was used with another template. |
| `TEMPLATE_SUBMISSION_IN_PROGRESS` | 409 | A submission of this name and language, with this key or another, is running or unconfirmed. Wait, then repeat it with the key it was made with. |
| `TEMPLATE_SUBMISSION_UNCONFIRMED` | 409, 502 | Meta hasn't confirmed the submission. Repeat it with the same key and body. If a 409 keeps coming back, Meta doesn't have the template: submit it under another name. |
| `WHATSAPP_CONNECTION_CHANGED` | 409 | The workspace connected another WhatsApp Business Account since. Submit again with a new key. |
| `WHATSAPP_LOOKUP_FAILED` | 502 | Meta couldn't be asked about the submission. Repeat it with the same key and body. |
| `WHATSAPP_RATE_LIMITED` | 503 | WhatsApp is limiting submissions. Wait, then repeat it with the same key and body. |

## Statuses

| Status | What it means | Retry? |
| --- | --- | --- |
| 400 | A parameter, body field, cursor or date range is invalid, or a key without `messages:read` subscribes to message events. | No. Fix the request. |
| 401 | The key is missing, invalid, expired or revoked. | No, except `Invalid API key`. |
| 402 | Sending is paused for the workspace. | No. |
| 403 | The key lacks a scope, WhatsApp has to be reconnected, or its account can't create templates. | No. |
| 404 | It doesn't exist in the key's workspace, or the workspace has no connected WhatsApp number. | No. |
| 409 | A template submission conflicts with an earlier one. | As its code says. |
| 413 | The body is larger than 100 KB. | No. |
| 429 | Too many requests with this key. | Yes, after `Retry-After` seconds. |
| 500 | Something failed in Chatwise, or WhatsApp didn't accept a message you sent. | Reads: yes, with growing waits. Template creation: yes, with the same key and body. Sends: see below. |
| 502, 503 | Meta didn't confirm a template submission, or is busy. | Template creation: yes, with the same key and body. Sends: see below. |

## Sends aren't retried safely

The two send routes have no idempotency key. After a timeout, or a 500, 502 or 503, read the conversation's messages before you send again. If the message is there, it was sent. If it isn't, it may still have been sent.

When WhatsApp doesn't accept a message, the answer is a 500 whose `message` starts with `Internal server error: WhatsApp send failed:`, followed by Meta's HTTP status and, when that was JSON, Meta's answer:

- **429:** try again later.
- **5xx:** check the conversation first, as above.
- **Anything else:** fix what the answer names. The same request will fail again.

A send that isn't accepted can still create the customer's conversation, without a message.
