UNPKG

zdata-client

Version:

TypeScript client library for zdata backend API with authentication and full CRUD operations

62 lines 1.98 kB
/** * @fileoverview Type definitions for the zdata-client library */ // ============================================================================= // CUSTOM ERROR CLASSES // ============================================================================= /** * Error thrown when authentication credentials are invalid */ export class InvalidCredentialsError extends Error { constructor(message = "Invalid credentials") { super(message); this.name = "InvalidCredentialsError"; Object.setPrototypeOf(this, InvalidCredentialsError.prototype); } } /** * Error thrown when request data fails validation */ export class ValidationError extends Error { constructor(message = "Validation error", errors = []) { super(message); this.name = "ValidationError"; this.errors = errors; Object.setPrototypeOf(this, ValidationError.prototype); } } /** * General API client error for HTTP and network issues */ export class ApiClientError extends Error { constructor(message, statusCode) { super(message); this.name = "ApiClientError"; if (statusCode !== undefined) { this.statusCode = statusCode; } Object.setPrototypeOf(this, ApiClientError.prototype); } } // ============================================================================= // TYPE GUARDS // ============================================================================= /** * Type guard to check if an error is an InvalidCredentialsError */ export function isInvalidCredentialsError(error) { return error instanceof InvalidCredentialsError; } /** * Type guard to check if an error is a ValidationError */ export function isValidationError(error) { return error instanceof ValidationError; } /** * Type guard to check if an error is an ApiClientError */ export function isApiClientError(error) { return error instanceof ApiClientError; } //# sourceMappingURL=types.js.map