Skip to content

Commit

Permalink
fix: add error throwing when socket encounters an error
Browse files Browse the repository at this point in the history
  • Loading branch information
LwveMike committed Apr 18, 2024
1 parent 7c33e7c commit 6257c64
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/tacacs-plus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
Expand Down
1 change: 1 addition & 0 deletions packages/tacacs-plus/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class Client {
socket.on('error', (err) => {
this.#logger.error(err.message)
socket.destroy()
throw err
})

socket.on('end', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/tacacs-plus/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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]
})
}

0 comments on commit 6257c64

Please sign in to comment.