The SDK throws typed errors for different HTTP status codes. All errors extend SocialRouterError.

Error classes

ClassHTTP StatusWhen
AuthenticationError401Invalid or missing API key
InsufficientCreditsError402Not enough credits for the extraction
RateLimitError429Rate limit or per-key credit limit exceeded
SocialRouterErrorOtherAny other API error

Usage

import {
  SocialRouter,
  SocialRouterError,
  AuthenticationError,
  InsufficientCreditsError,
  RateLimitError,
} from "@socialrouter/sdk";

const sr = new SocialRouter({ apiKey: "sr_live_your_key" });

try {
  const extraction = await sr.extract({
    url: "https://linkedin.com/in/example",
    provider: "apify/linkedin/profile.info",
  });
} catch (err) {
  if (err instanceof RateLimitError) {
    // err.retryAfter — seconds until the rate limit resets
    console.log(`Rate limited. Retry after ${err.retryAfter}s`);
  } else if (err instanceof InsufficientCreditsError) {
    console.log("Add credits:", err.message);
  } else if (err instanceof AuthenticationError) {
    console.log("Check your API key:", err.message);
  } else if (err instanceof SocialRouterError) {
    console.log(`API error [${err.code}]: ${err.message}`);
  }
}

Error properties

All error classes share these properties:
PropertyTypeDescription
messagestringHuman-readable error message
codestringMachine-readable code (e.g., insufficient_credits)
typestringError category (billing, validation, provider, rate_limit)
statusnumberHTTP status code
RateLimitError has an additional property:
PropertyTypeDescription
retryAfternumber | undefinedSeconds until the rate limit window resets