Skip to main content
The SDK throws typed error classes for different failure scenarios. All errors extend RoyaltyportError, which extends the built-in Error class.

Error Classes

ClassHTTP StatusDescription
RoyaltyportErrorAnyBase error class for all API errors
RoyaltyportAuthenticationError401Missing, invalid, or expired token
RoyaltyportRateLimitError429Rate limit exceeded
RoyaltyportValidationError400Invalid or missing parameters

Properties

All error classes include:
PropertyTypeDescription
messagestringHuman-readable error description
statusnumberHTTP status code
rateLimitobject or undefinedRate limit information from the response
RoyaltyportRateLimitError also includes:
PropertyTypeDescription
retryAfternumber or undefinedUnix timestamp when the rate limit resets

Usage

import {
  Royaltyport,
  RoyaltyportAuthenticationError,
  RoyaltyportRateLimitError,
  RoyaltyportValidationError,
} from '@royaltyport/sdk';

const royaltyport = new Royaltyport({ apiKey: 'rp_your_token_here' });

try {
  const { data } = await royaltyport.projects.list();
} catch (error) {
  if (error instanceof RoyaltyportAuthenticationError) {
    console.error('Invalid or expired token');
  } else if (error instanceof RoyaltyportRateLimitError) {
    console.error(`Rate limited. Retry after: ${error.retryAfter}`);
  } else if (error instanceof RoyaltyportValidationError) {
    console.error('Invalid request:', error.message);
  } else {
    throw error;
  }
}

Automatic Retries

The SDK automatically retries requests on 429 and 5xx errors:
  • Up to 3 retries per request
  • Exponential backoff starting at 500ms (max 60s)
  • Retry-After headers from rate limit responses are respected
No configuration is required. If all retries are exhausted, the corresponding error is thrown.