Skip to main content

Exceptions

Every SDK call that talks to the network can throw NotificationHubException (unchecked — extends RuntimeException) or one of its typed subclasses. A single factory method, NotificationHubException.create(message, statusCode, body), picks the right subclass based on the HTTP status code returned by the API.

Hierarchy

Status code mapping

HTTP statusException
401, 403NotificationHubAuthException
429NotificationHubRateLimitException
400499 (other)NotificationHubValidationException
500599NotificationHubServerException
Anything else / network failureNotificationHubException (status code 0 for local execution failures)

Fields

FieldAccessorDescription
status codegetStatusCode()The HTTP status returned, or 0 for a local/network failure.
response bodygetResponseBody()The raw response body, if any.

Handling exceptions

try {
client.notifications().send(request);
} catch (NotificationHubException.NotificationHubAuthException e) {
// Invalid or expired API key/secret — check your credentials
} catch (NotificationHubException.NotificationHubValidationException e) {
// Bad request — inspect e.getResponseBody() for details
} catch (NotificationHubException.NotificationHubRateLimitException e) {
// Back off and retry later
} catch (NotificationHubException.NotificationHubServerException e) {
// Transient server-side error — safe to retry with backoff
} catch (NotificationHubException e) {
// Network failure or unclassified error — e.getStatusCode() == 0 for local failures
}