Skip to main content

Error Handling

Both SDKs map every non-2xx HTTP response to the same four categories, via the identical status-code rules described in Java Exceptions and Node.js Exceptions.

CategoryStatus codesRecommended action
Auth401, 403Don't retry as-is. Check the key/secret you configured — see Authentication.
ValidationOther 4xxDon't retry as-is. Fix the request based on the response body.
Rate limit429Retry after a delay, ideally with exponential backoff.
Server5xxSafe to retry with backoff — the failure is likely transient.
Network / localN/A (status code 0)Retry with backoff; this covers connection failures and local serialization errors.

Example: retry with backoff

int maxAttempts = 3;
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
try {
client.notifications().send(request);
break;
} catch (NotificationHubException.NotificationHubRateLimitException
| NotificationHubException.NotificationHubServerException e) {
if (attempt == maxAttempts) throw e;
Thread.sleep((long) Math.pow(2, attempt) * 1000);
}
}

Idempotency and retries

When retrying a send, pass the same idempotency key on every attempt (see sendWithIdempotency) so a retry after a network timeout can't result in a duplicate notification if the original request actually succeeded server-side.