title: How to read status code from rejected WebSocket opening handshake with JavaScript?
body: <p>I created a WebSocket client in JavaScript</p>
  
  <pre><code>if ("WebSocket" in window) {            
      ws = new WebSocket(url);
      ws.binaryType = "arraybuffer";      
  } else if ("MozWebSocket" in window) {  
      ws = new MozWebSocket(url);
      ws.binaryType = "arraybuffer";  
  }
  </code></pre>
  
  <p>and a WebSocket server application. For certain cases I programmed the server to reject the connection request and provide an error code.</p>
  
  <p>In e.g. Firefox Console then a message is shown </p>
  
  <pre><code>Firefox can't establish a connection to the server at ws://123.123.123.123:1234/.
  </code></pre>
  
  <p>and it provides the status code </p>
  
  <pre><code>HTTP/1.1 403 
  </code></pre>
  
  <p>which is the error code that I have sent by my WebSocket server.</p>
  
  <p>My question is: how can I read this status code in my JavaScript client?</p>
  
  <pre><code>ws.onerror = function(e) {
      console.log(e);     
  };   
  ws.onclose = function(e) {
      console.log(e); 
  };
  </code></pre>
  
  <p>are both called, but none of the Event objects contains this error code.</p>