The error Event
the onerror
handler receives is a simple event not containing such information:
If the user agent was required to fail the WebSocket connection or the WebSocket connection is closed with prejudice, fire a simple event named error at the WebSocket object.
You may have better luck listening for the close
event, which is a CloseEvent
and indeed has a CloseEvent.code
property containing a numerical code according to RFC 6455 11.7 and a CloseEvent.reason
string property.
Please note however, that CloseEvent.code
(and CloseEvent.reason
) are limited in such a way that network probing and other security issues are avoided.