Skip to content
DocsSDKErrors & pagination

Errors & pagination

Updated Jul 2026·1 min

Every failure throws a typed MedalApiError with an HTTP status and a stable code; list endpoints paginate with cursors.

The API Keys tab in Personal Settings, with one workspace key and the Create API Key button.The API Keys tab in Personal Settings, with one workspace key and the Create API Key button.

Quick example

Type-checked against @medalsocial/sdk v1.3.0 (2026-07-20). A release that changes a signature fails this page's build.

ts
import { Medal, MedalApiError } from '@medalsocial/sdk';

const medal = new Medal(process.env.MEDAL_API_KEY as string);

// Every error is a typed MedalApiError with an HTTP status and a stable code
try {
  await medal.posts.publish('post_does_not_exist');
} catch (error) {
  if (error instanceof MedalApiError) {
    console.error(error.status, error.code, error.message);
  } else {
    throw error;
  }
}

// List endpoints paginate with cursors — loop until has_more is false
let cursor: string | undefined;
do {
  const { data, pagination } = await medal.contacts.list({ limit: 100, cursor });
  console.log(data.length, 'contacts');
  cursor = pagination.next_cursor ?? undefined;
  if (!pagination.has_more) break;
} while (cursor);

MedalApiError

Thrown for every non-2xx response. status is the HTTP status; code is a stable machine-readable string; details carries endpoint-specific context when available.

ts
declare class MedalApiError extends Error {
  readonly status: number;
  readonly code: string;
  readonly details?: unknown;
}

PaginatedResponse<T>

List endpoints return data plus a pagination envelope. Pass next_cursor back as cursor until has_more is false.

ts
interface PaginatedResponse<T> {
  data: T[];
  pagination: { has_more: boolean; next_cursor: string | null };
}