Handling Errors

Robust error handling is critical for push notifications. jxpush returns unified error structures regardless of the underlying provider.

Single Send Result

The send() method returns a SendResult object.

typescript
interface SendResult {
    success: boolean;
    messageId?: string; // If successful
    error?: Error;      // If failed
    provider: ProviderType;
}

Common Errors

  • Invalid Token: The device token is malformed or expired. You should remove this token from your database.
  • Quota Exceeded: You have sent too many messages quickly. Configure use the rateLimit option to prevent this.
  • Authentication Error: FCM service account or Expo access token is invalid.

Retry Logic

By default, jxpush will automatically retry transient errors (like network timeouts or 503 responses) with exponential backoff.

typescript
const client = new PushClient({
    // ...
    retry: {
        maxAttempts: 3,
        initialDelayMs: 1000,
        maxDelayMs: 30000,
        enabled: true
    }
});