Skip to content

Errors and retries ​

Errors ​

A request MsGine refuses raises one error type with:

Field
statusHTTP status, or 0 when MsGine could not be reached
codeStable code to branch on (table below)
messageReadable explanation
detailsField problems for validation errors, each with a message
retryAfterSeconds to wait, on rate limits
CodeStatusMeaning
validation_error400The request is invalid, or the balance is too low. See message and details.
unauthorized401Missing, wrong or revoked API key, or a bad signature.
forbidden403The key lacks the scope, or the sender domain is not verified.
not_found404No such resource in your account.
conflict409The resource is not in a state that allows this, for example cancelling a finished run.
rate_limit_exceeded429Too many requests for this key.
internal_error500A fault on MsGine's side.
connection_error0Network failure before an answer.
timeout0No answer within the timeout.
ts
import { MsGineError } from '@msgine/sdk';

try {
  await msgine.sms.send({ to: '+256701234567', message: 'Hello' });
} catch (error) {
  if (error instanceof MsGineError && error.code === 'validation_error') {
    console.error(error.message, error.details);
  } else {
    throw error;
  }
}
python
from msgine import MsGineError

try:
    msgine.sms.send(to="+256701234567", message="Hello")
except MsGineError as error:
    if error.code != "validation_error":
        raise
    print(error.message, error.details)
go
_, err := client.SMS.Send(ctx, msgine.SendSMSParams{To: []string{"+256701234567"}, Message: "Hello"})
var apiErr *msgine.Error
if errors.As(err, &apiErr) && apiErr.Code == "validation_error" {
	log.Println(apiErr.Message, apiErr.Details)
}

Retries and idempotency ​

The SDKs retry, up to maxRetries times (2 by default):

  • Rate limits (429) for every request, after the Retry-After the API sends.
  • Server errors (5xx), timeouts and network failures for reads, updates, deletes and sends.

Waits grow from one second to eight, with some randomness.

A failed send may have reached MsGine before the connection dropped. To make retrying safe, every send carries an idempotencyKey. When you do not pass one, the SDK generates one per call and reuses it on each attempt. MsGine returns the first result for a key it has already seen instead of sending again.

Pass your own key when the same logical message could be sent by two separate calls, for example when your job runner retries a whole job:

ts
await msgine.sms.send({ to, message, idempotencyKey: `order-${order.id}-shipped` });
python
msgine.sms.send(to=to, message=message, idempotency_key=f"order-{order.id}-shipped")
go
client.SMS.Send(ctx, msgine.SendSMSParams{To: to, Message: message, IdempotencyKey: "order-" + orderID + "-shipped"})

Keys are up to 64 characters (100 for events and workflow runs).

Calls that create or change something without an idempotency key, such as creating a webhook or publishing a workflow, are not retried after a server error: the first attempt may have worked. They are still retried after a rate limit, which MsGine applies before doing anything.

Released under the MIT License.