vapor / websocket-kit

WebSocket client library built on SwiftNIO

Home Page:https://docs.vapor.codes/4.0/advanced/websockets/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server-side error codes not available to WebSocket class

bridger opened this issue · comments

I ran into an issue where a NIOWebSocketError.invalidFrameLength error was thrown, but WebSocket.closeCode is nil and WebSocket.isClosed is false.

It seems that errors thrown and caught by the NIO framework don't make their way back to the WebSocket class. The WebSocket.onClose Future is triggered, but I don't know how to get the error code at that point.

I also see that when the onClose future is fulfilled I also need to manually close the websocket, or else this assertion will trigger:

deinit {
    assert(self.isClosed, "WebSocket was not closed before deinit.")
}

I see that when the error is thrown the WebSocketProtocolErrorHandler in NIO catches and sends the appropriate close code back over the channel. Is there some way to surface this to the WebSocket class as well?

Sorry if I'm just misunderstanding the API. I'm switch to Vapor from Kitura, but I'm really liking what I see so far!