import type { Cid } from '@atcute/lexicons'; export type SdkErrorCode = | 'ERR_NIB_PATH' | 'ERR_NIB_IDENTITY' | 'ERR_NIB_RECORD_INVALID' | 'ERR_NIB_BLOB_INVALID' | 'ERR_NIB_BASE_REQUIRED' | 'ERR_NIB_NOT_OWNER' | 'ERR_NIB_CONFLICT' | 'ERR_NIB_LIMIT' | 'ERR_NIB_SLUG' | 'ERR_NIB_SLUG_TAKEN' | 'ERR_NIB_NOT_FOUND' | 'ERR_NIB_AUTH_LOOPBACK'; export class SdkError extends Error { readonly code: SdkErrorCode; constructor(message: string, code: SdkErrorCode, options?: ErrorOptions) { super(message, options); this.name = 'SdkError'; this.code = code; } } export class PathError extends SdkError { readonly path: string; constructor(message: string, path: string) { super(message, 'ERR_NIB_PATH'); this.name = 'PathError'; this.path = path; } } /** Someone else saved the project after it was loaded. `remote` is the record's current CID, or undefined if it was deleted. */ export class ProjectConflictError extends SdkError { readonly uri: string; readonly remote: Cid | undefined; constructor(uri: string, remote: Cid | undefined) { super(`project ${uri} changed since it was loaded`, 'ERR_NIB_CONFLICT'); this.name = 'ProjectConflictError'; this.uri = uri; this.remote = remote; } } /** Another of the author's projects already uses `slug`. Creating picks a free one instead; renaming throws this. */ export class SlugTakenError extends SdkError { readonly slug: string; /** The project that has the slug. */ readonly uri: string; constructor(slug: string, uri: string) { super(`another project already uses the slug ${JSON.stringify(slug)}`, 'ERR_NIB_SLUG_TAKEN'); this.name = 'SlugTakenError'; this.slug = slug; this.uri = uri; } }