UNPKG

portfree

Version:

A cross-platform CLI tool for managing processes running on specific ports

47 lines 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NetworkError = void 0; /** * Custom error class for network-related errors * Used when network operations fail or ports are unreachable */ class NetworkError extends Error { /** * Create a new NetworkError * @param message - Error message describing the network issue * @param port - Port number related to the network error (optional) * @param operation - Network operation that failed (optional) */ constructor(message, port = null, operation = null) { super(message); this.name = 'NetworkError'; this.code = 'NETWORK_ERROR'; this.port = port; this.operation = operation; // Maintains proper stack trace for where our error was thrown (only available on V8) if (Error.captureStackTrace) { Error.captureStackTrace(this, NetworkError); } } /** * Get user-friendly error message with suggestions * @returns Formatted error message */ getUserMessage() { let message = this.message; if (this.port) { message += ` (Port: ${this.port})`; } if (this.operation) { message += ` (Operation: ${this.operation})`; } message += '\n\nSuggestions:'; message += '\n- Check your network connection'; message += '\n- Verify the port number is correct and accessible'; message += '\n- Ensure no firewall is blocking the connection'; message += '\n- Try again in a few moments'; return message; } } exports.NetworkError = NetworkError; //# sourceMappingURL=network-error.js.map