max-mapper / websocket-stream

websockets with the node stream API
BSD 2-Clause "Simplified" License
667 stars 114 forks source link

propagate CloseEvent on un-cleanly closed connections #125

Closed mvayngrib closed 7 years ago

mvayngrib commented 7 years ago

CloseEvent has additional error information that is not available in onerror

mcollina commented 7 years ago

Can you please add in the description why this is a better error than before? Make an example?

mvayngrib commented 7 years ago

@mcollina i did some more reading about the CloseEvent, and even though it has a code and reason, the spec seems to mandate that that code and reason give nearly zero information, for security reasons. I should have spotted that earlier. Basically, code will typically be 1006 if onerror fired, and reason an empty string.

for an example, you can see this: https://github.com/websockets/ws/blob/master/test/WebSocket.test.js#L1045

in the end, this change may be only an improvement in a few edge cases, so it's not as useful as i thought it'd be