Errors
What the SDK returns, and what to do about it.
A call that fails returns one of three error types. Read them with errors.As. The API's own codes are listed in
Errors.
| Error | When |
|---|---|
*APIError | The API answered with an error. |
*ConnectionError | No answer came: the network failed, or it took too long. |
*WebhookVerificationError | A webhook's signature or timestamp didn't check out. |
A canceled context returns its own error, context.Canceled or context.DeadlineExceeded.
Handle an error
_, err := client.Messages.SendOne(ctx, goomzo.MessageInput{To: "0712345678", Channel: goomzo.SMS, Content: &goomzo.Content{Text: "Hi"}})
var apiErr *goomzo.APIError
if errors.As(err, &apiErr) && apiErr.Code == "invalid" {
fmt.Println(apiErr.Fields["messages[0].to"].Message) // Add the country code…
}| Field | Description |
|---|---|
Status | The HTTP status, such as 400. |
Code | What went wrong, such as invalid, not_found or insufficient_sms. |
Message | What the API said, in words. |
Fields | The fields that were wrong, by where they are, such as customers[1].phone. |
RequestID | The request's id. Include it when you contact Goomzo. |
*ConnectionError has TimedOut, true when a try took longer than the timeout.
Retries
Network errors, 429 and 5xx are tried again before an error is returned, twice by default, waiting as long as
the API asks. Every POST carries the same Idempotency-Key on each try, so nothing is done twice.
Next steps
Last updated