getting the reason why websockets closed with close code 1006
Asked 07 September, 2021
Viewed 2.3K times
  • 60
Votes

I would like to get the reason websockets closed, so I can show the right message to the user.

I have

sok.onerror=function (evt) 
     {//since there is an error, sockets will close so...
       sok.onclose=function(e){
           console.log("WebSocket Error: " , e);}

The code is always 1006 and the reason is always " ". But I want to tell different closing reasons apart.

For example the comand line gives an error reason : "you cannot delete that, because database wont let you". But on Chrome's console, the reason is still " ".

Any other way to tell different closing reasons apart?

6 Answer