From b0736014be634475dac4c23843811257d86dcdc1 Mon Sep 17 00:00:00 2001 From: James Hartt Date: Tue, 14 Jul 2020 00:41:57 +0100 Subject: [PATCH] Fix force try in connect method (#71) * Fail bit more gracefully * Remove log * Remove linux tests --- Sources/WebSocketKit/WebSocketClient.swift | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Sources/WebSocketKit/WebSocketClient.swift b/Sources/WebSocketKit/WebSocketClient.swift index 6ee4cebf..1eb4df78 100644 --- a/Sources/WebSocketKit/WebSocketClient.swift +++ b/Sources/WebSocketKit/WebSocketClient.swift @@ -91,14 +91,18 @@ public final class WebSocketClient { ) if scheme == "wss" { - let context = try! NIOSSLContext( - configuration: self.configuration.tlsConfiguration ?? .forClient() - ) - let tlsHandler = try! NIOSSLClientHandler(context: context, serverHostname: host) - return channel.pipeline.addHandler(tlsHandler).flatMap { - channel.pipeline.addHTTPClientHandlers(leftOverBytesStrategy: .forwardBytes, withClientUpgrade: config) - }.flatMap { - channel.pipeline.addHandler(httpHandler) + do { + let context = try NIOSSLContext( + configuration: self.configuration.tlsConfiguration ?? .forClient() + ) + let tlsHandler = try NIOSSLClientHandler(context: context, serverHostname: host) + return channel.pipeline.addHandler(tlsHandler).flatMap { + channel.pipeline.addHTTPClientHandlers(leftOverBytesStrategy: .forwardBytes, withClientUpgrade: config) + }.flatMap { + channel.pipeline.addHandler(httpHandler) + } + } catch { + return channel.pipeline.close(mode: .all) } } else { return channel.pipeline.addHTTPClientHandlers(