/** Safe string for logs / sendError from thrown values */
export function errorMessage(err) {
    if (err instanceof Error)
        return err.message;
    if (typeof err === 'string')
        return err;
    try {
        return JSON.stringify(err);
    }
    catch {
        return String(err);
    }
}
/**
 * Same extraction logic as the legacy `gateway.connect` catch (axios + Node err shapes).
 */
export function parseGatewayConnectFailure(raw) {
    let errorMessage = 'Unknown error occurred';
    let errorCode = '';
    if (typeof raw === 'string') {
        return { errorMessage: raw, errorCode: '' };
    }
    if (!raw || typeof raw !== 'object') {
        return { errorMessage: String(raw), errorCode: '' };
    }
    const error = raw;
    if (error.message) {
        errorMessage = error.message;
    }
    else if (error.response?.data?.message) {
        errorMessage = error.response.data.message;
    }
    else if (error.response?.statusText) {
        errorMessage = `${error.response.status} ${error.response.statusText}`;
    }
    else if (error.code) {
        errorCode = error.code;
        errorMessage = `Connection error: ${error.code}`;
    }
    return { errorMessage, errorCode };
}
//# sourceMappingURL=tui-handlers-errors.js.map