Errors and retries
Errors
A request MsGine refuses raises one error type with:
| Field | |
|---|---|
status | HTTP status, or 0 when MsGine could not be reached |
code | Stable code to branch on (table below) |
message | Readable explanation |
details | Field problems for validation errors, each with a message |
retryAfter | Seconds to wait, on rate limits |
| Code | Status | Meaning |
|---|---|---|
validation_error | 400 | The request is invalid, or the balance is too low. See message and details. |
unauthorized | 401 | Missing, wrong or revoked API key, or a bad signature. |
forbidden | 403 | The key lacks the scope, or the sender domain is not verified. |
not_found | 404 | No such resource in your account. |
conflict | 409 | The resource is not in a state that allows this, for example cancelling a finished run. |
rate_limit_exceeded | 429 | Too many requests for this key. |
internal_error | 500 | A fault on MsGine's side. |
connection_error | 0 | Network failure before an answer. |
timeout | 0 | No answer within the timeout. |
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;
}
}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)_, 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-Afterthe 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:
await msgine.sms.send({ to, message, idempotencyKey: `order-${order.id}-shipped` });msgine.sms.send(to=to, message=message, idempotency_key=f"order-{order.id}-shipped")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.