From 6257c6475e06ff3950470a3760b29329247dd35e Mon Sep 17 00:00:00 2001 From: lwvemike Date: Thu, 18 Apr 2024 13:26:56 +0300 Subject: [PATCH] fix: add error throwing when socket encounters an error --- packages/tacacs-plus/package.json | 1 - packages/tacacs-plus/src/client/index.ts | 1 + packages/tacacs-plus/src/utils.ts | 8 ++++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/tacacs-plus/package.json b/packages/tacacs-plus/package.json index 36a9447..df62e2f 100644 --- a/packages/tacacs-plus/package.json +++ b/packages/tacacs-plus/package.json @@ -22,7 +22,6 @@ "sideEffects": false, "exports": { ".": { - "types": "./dist/index.d.ts", "import": { "types": "./dist/index.d.mts", "default": "./dist/index.mjs" diff --git a/packages/tacacs-plus/src/client/index.ts b/packages/tacacs-plus/src/client/index.ts index cc2f0cc..04e8087 100644 --- a/packages/tacacs-plus/src/client/index.ts +++ b/packages/tacacs-plus/src/client/index.ts @@ -136,6 +136,7 @@ export class Client { socket.on('error', (err) => { this.#logger.error(err.message) socket.destroy() + throw err }) socket.on('end', () => { diff --git a/packages/tacacs-plus/src/utils.ts b/packages/tacacs-plus/src/utils.ts index 5931763..d044e6d 100644 --- a/packages/tacacs-plus/src/utils.ts +++ b/packages/tacacs-plus/src/utils.ts @@ -1,4 +1,5 @@ import type { Versions } from './header/types' +import type { Arg } from './types' /** * @description Creates a version value using the major and minor versions. @@ -58,3 +59,10 @@ export function noop(_message: string) { /* empty */ } export function createVersionByte({ majorVersion, minorVersion }: Versions) { return ((majorVersion & 0xF) << 4) | (minorVersion & 0xF) } + +export function getArgsKeyValuePairs(args: Arg[]): Array<[key: string, value: string]> { + return args + .map((arg) => { + return arg.split('=') as [key: string, value: string] + }) +}