Able to catch exceptions from one transport and fall back to the other

This commit is contained in:
Glen Maddern 2025-04-17 16:04:50 +10:00
parent 0bf84d5d22
commit 14109a309f
5 changed files with 104 additions and 51 deletions

View file

@ -70,7 +70,15 @@ async function runClient(
try {
// Connect to remote server with authentication
const transport = await connectToRemoteServer(serverUrl, authProvider, headers, waitForAuthCode, skipBrowserAuth, transportStrategy)
const transport = await connectToRemoteServer(
client,
serverUrl,
authProvider,
headers,
waitForAuthCode,
skipBrowserAuth,
transportStrategy,
)
// Set up message and error handlers
transport.onmessage = (message) => {
@ -94,9 +102,6 @@ async function runClient(
}
setupSignalHandlers(cleanup)
// Connect the client
log('Connecting client...')
await client.connect(transport)
log('Connected successfully!')
try {
@ -117,7 +122,10 @@ async function runClient(
log('Error requesting resources list:', e)
}
log('Listening for messages. Press Ctrl+C to exit.')
// log('Listening for messages. Press Ctrl+C to exit.')
log('Exiting OK...')
server.close()
process.exit(0)
} catch (error) {
log('Fatal error:', error)
server.close()