MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / parseIpAndPort

Function parseIpAndPort

src/lib/live-logging.ts:63–84  ·  view source on GitHub ↗
(address: string)

Source from the content-addressed store, hash-verified

61}
62
63export const parseIpAndPort = (address: string): [string, string | undefined] => {
64 const items = address.split(':')
65 if (items.length > 2) {
66 return fatalError('Invalid IPv4 address and port format.')
67 }
68
69 if (!net.isIPv4(items[0])) {
70 return fatalError('Invalid IPv4 address format.')
71 }
72
73 const ipv4 = items[0]
74 if (items.length == 1) {
75 return [ipv4, undefined]
76 }
77
78 const port = Number(items[1])
79 if (Number.isInteger(port) && port >= 0 && port <= 65535) {
80 return [ipv4, port.toString()]
81 }
82
83 return fatalError('Invalid port format.')
84}
85
86export const handleConnectionErrors = (authority: string, error: string): never | void => {
87 const generalMessage = 'Ensure hub address is correct and try again'

Callers 2

handlerFunction · 0.85

Calls 1

fatalErrorFunction · 0.85

Tested by

no test coverage detected