Exceptions
Every SDK call that talks to the network can reject with a NotificationHubError or one of its typed subclasses, all defined in exception/NotificationHubError.ts. The static factory NotificationHubError.create(message, statusCode, body) picks the right subclass based on the HTTP status code returned by the API.
Hierarchy
Status code mapping
| HTTP status | Error |
|---|---|
401, 403 | NotificationHubAuthError |
429 | NotificationHubRateLimitError |
400–499 (other) | NotificationHubValidationError |
500–599 | NotificationHubServerError |
| Anything else / network failure | NotificationHubError (status code 0 for local execution failures) |
Fields
| Field | Description |
|---|---|
statusCode | The HTTP status returned, or 0 for a local/network failure. |
responseBody | The raw response body, if any. |
Handling errors
import {
NotificationHubAuthError,
NotificationHubValidationError,
NotificationHubRateLimitError,
NotificationHubServerError,
NotificationHubError,
} from '@sumitshresht/notificationhub-sdk';
try {
await client.notifications().send(request);
} catch (error) {
if (error instanceof NotificationHubAuthError) {
// Invalid or expired API key/secret — check your credentials
} else if (error instanceof NotificationHubValidationError) {
// Bad request — inspect error.responseBody for details
} else if (error instanceof NotificationHubRateLimitError) {
// Back off and retry later
} else if (error instanceof NotificationHubServerError) {
// Transient server-side error — safe to retry with backoff
} else if (error instanceof NotificationHubError) {
// Network failure or unclassified error — error.statusCode === 0 for local failures
} else {
throw error;
}
}