الانتقال إلى المحتوى
DocsSDKالأخطاء والتقسيم

الأخطاء والتقسيم

تم التحديث يوليو 2026·1 min

كل فشل يرمي MedalApiError مُنمّطًا بحالة HTTP وكود ثابت؛ ونقاط الاستعراض تُقسّم النتائج بمؤشرات.

تبويب مفاتيح API في الإعدادات الشخصية، مع مفتاح واحد وزر إنشاء مفتاح.تبويب مفاتيح API في الإعدادات الشخصية، مع مفتاح واحد وزر إنشاء مفتاح.

مثال سريع

مُدقّق الأنواع مقابل ‎@medalsocial/sdk v1.3.0 (2026-07-20). أي إصدار يغيّر توقيعًا يوقف بناء هذه الصفحة.

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 };
}