TheIntroDB Package Docs

Documentation for the theintrodb NPM package

View on GitHub

Errors And Validation

Error Classes

TheIntroDbValidationError

Thrown when input validation fails before a request is sent.

Common cases:

TheIntroDbResponseValidationError

Thrown when the server returns JSON that does not match the expected schema.

Common cases:

TheIntroDbApiError

Thrown when the API responds with a non-2xx status.

Useful properties:

Validation Layers

This package validates in three places:

  1. Before sending requests
  2. After receiving JSON responses
  3. During timestamp normalization

Time handling is one of the main validation responsibilities of the package.

Before a submission is sent, the package validates:

During parsing and normalization, the package also preserves the meaning of API time values:

Rate Limit Metadata

TheIntroDbApiError.rateLimit contains parsed values from these headers when present:

Example Error Handling

import {
  TheIntroDbApiError,
  TheIntroDbResponseValidationError,
  TheIntroDbValidationError,
} from 'theintrodb';

try {
  await client.submitMediaTimestamp(
    {
      tmdbId: 12345,
      type: 'movie',
      segment: 'intro',
      startSec: 0,
      endSec: 90,
    },
    {
      apiKey: currentUserApiKey,
    }
  );
} catch (error) {
  if (error instanceof TheIntroDbValidationError) {
    console.error('Input problem:', error.issues);
  } else if (error instanceof TheIntroDbResponseValidationError) {
    console.error('Unexpected API response:', error.body);
  } else if (error instanceof TheIntroDbApiError) {
    console.error('API failure:', error.status, error.code, error.rateLimit);
  } else {
    throw error;
  }
}