Improves error handling on WebSocket connections. Improvements to WebSocket-Kit intercept errors or timeouts at the ChannelHandler level and expose them to the WebSocket class.
Now, when an error occurs (such as a malformed WebSocket frame) the error is available via the closeCode on WebSocket. Example:
func connected(request: Request, connection: WebSocket) {
_ = connection.onClose.always { (result) in
let closeReason = connectionInfo.connection.closeCode ?? .unknown(0)
// Application-specific cleanup code here
}
}
This patch was authored by @bridger and released by @tanner0101.