zdata-client
Version:
TypeScript client library for zdata backend API with authentication and full CRUD operations
71 lines • 2.4 kB
JavaScript
;
/**
* @fileoverview Type definitions for the zdata-client library
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiClientError = exports.ValidationError = exports.InvalidCredentialsError = void 0;
exports.isInvalidCredentialsError = isInvalidCredentialsError;
exports.isValidationError = isValidationError;
exports.isApiClientError = isApiClientError;
// =============================================================================
// CUSTOM ERROR CLASSES
// =============================================================================
/**
* Error thrown when authentication credentials are invalid
*/
class InvalidCredentialsError extends Error {
constructor(message = "Invalid credentials") {
super(message);
this.name = "InvalidCredentialsError";
Object.setPrototypeOf(this, InvalidCredentialsError.prototype);
}
}
exports.InvalidCredentialsError = InvalidCredentialsError;
/**
* Error thrown when request data fails validation
*/
class ValidationError extends Error {
constructor(message = "Validation error", errors = []) {
super(message);
this.name = "ValidationError";
this.errors = errors;
Object.setPrototypeOf(this, ValidationError.prototype);
}
}
exports.ValidationError = ValidationError;
/**
* General API client error for HTTP and network issues
*/
class ApiClientError extends Error {
constructor(message, statusCode) {
super(message);
this.name = "ApiClientError";
if (statusCode !== undefined) {
this.statusCode = statusCode;
}
Object.setPrototypeOf(this, ApiClientError.prototype);
}
}
exports.ApiClientError = ApiClientError;
// =============================================================================
// TYPE GUARDS
// =============================================================================
/**
* Type guard to check if an error is an InvalidCredentialsError
*/
function isInvalidCredentialsError(error) {
return error instanceof InvalidCredentialsError;
}
/**
* Type guard to check if an error is a ValidationError
*/
function isValidationError(error) {
return error instanceof ValidationError;
}
/**
* Type guard to check if an error is an ApiClientError
*/
function isApiClientError(error) {
return error instanceof ApiClientError;
}
//# sourceMappingURL=types.js.map