/** * Custom error classes for browser automation and profiles. * * @example * ```typescript * try { * await morph.browser.profiles.createProfile({ name: '', repoId: 'owner/repo' }); * } catch (e) { * if (e instanceof MorphValidationError) { * console.log('Validation failed:', e.field, e.message); * } else if (e instanceof MorphAPIError) { * console.log('API error:', e.code, e.statusCode); * } * } * ``` */ /** * Error codes for Morph Browser SDK */ type MorphErrorCode = 'validation_error' | 'invalid_parameter' | 'missing_required_field' | 'authentication_required' | 'invalid_api_key' | 'insufficient_permissions' | 'profile_not_found' | 'session_not_found' | 'resource_not_found' | 'profile_limit_exceeded' | 'rate_limit_exceeded' | 'session_expired' | 'session_save_failed' | 'network_error' | 'timeout' | 'service_unavailable'; /** * Base error class for all Morph SDK errors. */ declare class MorphError extends Error { /** Error code for programmatic handling */ readonly code: MorphErrorCode; /** Original cause of the error, if any */ readonly cause?: Error; constructor(message: string, code: MorphErrorCode, cause?: Error); /** * Returns a JSON representation of the error for logging. */ toJSON(): { name: string; message: string; code: MorphErrorCode; cause: string | undefined; }; } /** * Error thrown when API request validation fails. */ declare class MorphValidationError extends MorphError { /** The field that failed validation */ readonly field?: string; constructor(message: string, field?: string); toJSON(): { field: string | undefined; name: string; message: string; code: MorphErrorCode; cause: string | undefined; }; } /** * Error thrown when an API request fails. */ declare class MorphAPIError extends MorphError { /** HTTP status code */ readonly statusCode: number; /** Request ID for debugging (if available) */ readonly requestId?: string; /** Raw response body */ readonly rawResponse?: string; constructor(message: string, code: MorphErrorCode, statusCode: number, options?: { requestId?: string; rawResponse?: string; cause?: Error; }); toJSON(): { statusCode: number; requestId: string | undefined; name: string; message: string; code: MorphErrorCode; cause: string | undefined; }; } /** * Error thrown when authentication fails. */ declare class MorphAuthenticationError extends MorphAPIError { constructor(message?: string); } /** * Error thrown when rate limit is exceeded. */ declare class MorphRateLimitError extends MorphAPIError { /** When the rate limit resets (Unix timestamp) */ readonly resetAt?: number; /** Number of seconds until reset */ readonly retryAfter?: number; constructor(message?: string, options?: { resetAt?: number; retryAfter?: number; requestId?: string; }); toJSON(): { resetAt: number | undefined; retryAfter: number | undefined; statusCode: number; requestId: string | undefined; name: string; message: string; code: MorphErrorCode; cause: string | undefined; }; } /** * Error thrown when a resource is not found. */ declare class MorphNotFoundError extends MorphAPIError { /** The type of resource that was not found */ readonly resourceType: string; /** The ID of the resource that was not found */ readonly resourceId?: string; constructor(resourceType: string, resourceId?: string); toJSON(): { resourceType: string; resourceId: string | undefined; statusCode: number; requestId: string | undefined; name: string; message: string; code: MorphErrorCode; cause: string | undefined; }; } /** * Error thrown when profile limit is exceeded. */ declare class MorphProfileLimitError extends MorphAPIError { /** Current number of profiles */ readonly currentCount?: number; /** Maximum allowed profiles for the plan */ readonly maxAllowed?: number; constructor(message?: string, options?: { currentCount?: number; maxAllowed?: number; requestId?: string; }); toJSON(): { currentCount: number | undefined; maxAllowed: number | undefined; statusCode: number; requestId: string | undefined; name: string; message: string; code: MorphErrorCode; cause: string | undefined; }; } /** * Parse an API error response and return the appropriate error class. */ declare function parseAPIError(statusCode: number, responseText: string, requestId?: string): MorphAPIError; export { MorphAPIError, MorphAuthenticationError, MorphError, type MorphErrorCode, MorphNotFoundError, MorphProfileLimitError, MorphRateLimitError, MorphValidationError, parseAPIError };