UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

113 lines 3.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PolyVAuthenticationError = exports.PolyVConfigError = exports.PolyVAPIError = exports.PolyVValidationError = exports.PolyVError = exports.APIError = exports.ConfigurationError = exports.ValidationError = exports.CLIError = void 0; exports.formatError = formatError; exports.logError = logError; exports.handleUncaughtError = handleUncaughtError; exports.handleUnhandledRejection = handleUnhandledRejection; class CLIError extends Error { constructor(message, code = 'CLI_ERROR', statusCode = 1) { super(message); this.name = 'CLIError'; this.code = code; this.statusCode = statusCode; if (Error.captureStackTrace) { Error.captureStackTrace(this, CLIError); } } } exports.CLIError = CLIError; class ValidationError extends CLIError { constructor(message) { super(message, 'VALIDATION_ERROR', 1); this.name = 'ValidationError'; } } exports.ValidationError = ValidationError; class ConfigurationError extends CLIError { constructor(message) { super(message, 'CONFIG_ERROR', 1); this.name = 'ConfigurationError'; } } exports.ConfigurationError = ConfigurationError; class APIError extends CLIError { constructor(message, statusCode = 1) { super(message, 'API_ERROR', statusCode); this.name = 'APIError'; } } exports.APIError = APIError; class PolyVError extends CLIError { constructor(message, code = 'POLYV_ERROR', statusCode = 1, context) { super(message, code, statusCode); this.name = 'PolyVError'; this.context = context; } } exports.PolyVError = PolyVError; class PolyVValidationError extends PolyVError { constructor(message, field, value, rule, context) { super(message, 'POLYV_VALIDATION_ERROR', 1, context); this.name = 'PolyVValidationError'; this.field = field; this.value = value; this.rule = rule; } } exports.PolyVValidationError = PolyVValidationError; class PolyVAPIError extends PolyVError { constructor(message, code = 'POLYV_API_ERROR', httpStatus = 500, context) { super(message, code, httpStatus, context); this.name = 'PolyVAPIError'; this.httpStatus = httpStatus; this.apiResponse = context?.['responseData'] || context?.['polyvData']; } } exports.PolyVAPIError = PolyVAPIError; class PolyVConfigError extends PolyVError { constructor(message, context) { super(message, 'POLYV_CONFIG_ERROR', 1, context); this.name = 'PolyVConfigError'; } } exports.PolyVConfigError = PolyVConfigError; class PolyVAuthenticationError extends PolyVError { constructor(message, context) { super(message, 'POLYV_AUTH_ERROR', 1, context); this.name = 'PolyVAuthenticationError'; } } exports.PolyVAuthenticationError = PolyVAuthenticationError; function formatError(error) { if (error instanceof CLIError) { return `Error: ${error.message}`; } if (error.message.includes('ENOENT')) { return 'Error: File or directory not found'; } if (error.message.includes('EACCES')) { return 'Error: Permission denied'; } if (error.message.includes('ENOTDIR')) { return 'Error: Not a directory'; } return `Unexpected error: ${error.message}`; } function logError(error) { const formattedMessage = formatError(error); console.error(formattedMessage); if (process.env['NODE_ENV'] === 'development' || process.env['DEBUG']) { console.error('Stack trace:', error.stack); } } function handleUncaughtError(error) { logError(error); process.exit(1); } function handleUnhandledRejection(reason) { const error = reason instanceof Error ? reason : new Error(String(reason)); logError(error); process.exit(1); } //# sourceMappingURL=errors.js.map