Skip to main content

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 statusError
401, 403NotificationHubAuthError
429NotificationHubRateLimitError
400–499 (other)NotificationHubValidationError
500–599NotificationHubServerError
Anything else / network failureNotificationHubError (status code 0 for local execution failures)

Fields​

FieldDescription
statusCodeThe HTTP status returned, or 0 for a local/network failure.
responseBodyThe 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;
}
}