UNPKG

icom-wlan-node

Version:

Icom WLAN (CI‑V, audio) protocol implementation for Node.js/TypeScript.

65 lines (64 loc) 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConnectionAbortedError = void 0; exports.getDisconnectMessage = getDisconnectMessage; const types_1 = require("../types"); /** * Get human-readable message for a disconnect reason */ function getDisconnectMessage(reason) { switch (reason) { case types_1.DisconnectReason.USER_REQUEST: return 'Connection closed by user request'; case types_1.DisconnectReason.TIMEOUT: return 'Connection timed out'; case types_1.DisconnectReason.CLEANUP: return 'Connection cleanup'; case types_1.DisconnectReason.ERROR: return 'Connection closed due to error'; case types_1.DisconnectReason.NETWORK_LOST: return 'Network connection lost'; default: return 'Connection closed'; } } /** * Error thrown when a connection attempt is aborted * This is typically used when disconnect() is called during connect() */ class ConnectionAbortedError extends Error { constructor(reason, sessionId, phase, context) { super(getDisconnectMessage(reason)); this.reason = reason; this.sessionId = sessionId; this.phase = phase; this.context = context; this.name = 'ConnectionAbortedError'; // Maintains proper stack trace for where error was thrown (V8 only) if (Error.captureStackTrace) { Error.captureStackTrace(this, ConnectionAbortedError); } } /** * Check if this error should be silent (not thrown to user) * Cleanup and timeout errors during connect are typically expected */ isSilent() { return this.reason === types_1.DisconnectReason.CLEANUP || this.reason === types_1.DisconnectReason.TIMEOUT; } /** * Get detailed error information for debugging */ toJSON() { return { name: this.name, message: this.message, reason: this.reason, sessionId: this.sessionId, phase: this.phase, context: this.context }; } } exports.ConnectionAbortedError = ConnectionAbortedError;