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.

ErrorWhen
*APIErrorThe API answered with an error.
*ConnectionErrorNo answer came: the network failed, or it took too long.
*WebhookVerificationErrorA 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…
}
FieldDescription
StatusThe HTTP status, such as 400.
CodeWhat went wrong, such as invalid, not_found or insufficient_sms.
MessageWhat the API said, in words.
FieldsThe fields that were wrong, by where they are, such as customers[1].phone.
RequestIDThe 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