(address: string)
| 61 | } |
| 62 | |
| 63 | export 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 | |
| 86 | export const handleConnectionErrors = (authority: string, error: string): never | void => { |
| 87 | const generalMessage = 'Ensure hub address is correct and try again' |
no test coverage detected