Errors
One shape for every failure, and how to branch on it.
Every failure answers with the same envelope:
{
"code": "invalid_address",
"message": "none of the numbers is a valid phone number",
"error": {
"type": "invalid",
"code": "invalid_address",
"reason": "none of the numbers is a valid phone number",
"field": "to",
"retryable": false,
"request_id": "46fb5b754b141e69c55e764ed182d160"
}
}| Field | Use it for |
|---|---|
code | Branching. This is the contract, and it changes only with notice. |
type | Handling a whole class of failures at once. |
reason | Showing a person. It is reworded freely: never match on it. |
message | The same text as reason, at the top level. |
field | Which input to mark. |
resource | Which kind of thing was missing or not set up. |
retryable | Whether repeating the same request could work. |
request_id | Quoting to support. |
field, resource and reason are left out when empty. Several failures share a code and differ in field: switch on code, then use field to decide which input to mark.
Codes you will meet first
| Status | code | Meaning |
|---|---|---|
400 | missing_field | a required input was absent; field names it |
400 | invalid_value | outside the allowed set or breaking a limit. A body that is not JSON is this, with field: "Content-Type" |
400 | invalid_json | the body did not parse |
400 | unknown_field | a property this endpoint does not accept; field is the misspelling |
400 | invalid_address | a phone number would not parse |
401 | unauthorized | see Keys and scopes |
402 | insufficient_funds | the wallet cannot cover the send; nothing was sent |
403 | insufficient_scope | the key lacks the scope |
403 | sender_id_not_approved | your workspace may not send as this sender ID |
403 | forbidden | not allowed, such as a campaign sent with a test key |
404 | not_found | resource says what was missing |
409 | idempotency_key_reused | see Idempotency |
409 | idempotency_in_progress | the first request with this key is still running; retry shortly |
429 | rate_limited | see Rate limits |
502 | provider_rejected | the network refused the send; it is recorded as failed and not charged |
503 | provider_unavailable | the network did not answer; check the message's status before sending again |
Unknown properties are refused, not ignored, so a misspelled field never silently does nothing:
curl https://v3.ghala.io/v1/messages \
-H "Authorization: Bearer $GHALA_KEY" \
-H "Content-Type: application/json" \
-d '{"channel": "sms", "from": "ACME", "too": ["255700000001"], "type": "text", "text": "Hi"}'{
"code": "unknown_field",
"message": "the request body has a property this endpoint does not accept",
"error": { "type": "invalid", "code": "unknown_field", "field": "too", "retryable": false }
}retryable
It is true only for failures that are a matter of timing, such as rate_limited (after Retry-After), idempotency_in_progress, provider_unavailable, unavailable and internal. Everything else is false: repeating a request with a bad number will never succeed.
Our own failures and a provider's answer with a fixed sentence for the code, never internal detail. The detail is logged against the request_id.