socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

When a send a big data to server, I can't get 413 error by listen ‘disconnect’ event

Open shuntian opened this issue 1 year ago • 1 comments

socket.io: 4.6.1 socket.io-client: 4.6.1

shuntian avatar Aug 13 '24 10:08 shuntian

Hi! You can use the second argument of the disconnect event:

socket.on("disconnect", (reason, details) => {
  console.log(reason); // "transport error"

  // in that case, details is an error object
  console.log(details.message); "xhr post error"
  console.log(details.description); // 413 (the HTTP status of the response)

  // details.context refers to the XMLHttpRequest object
  console.log(details.context.status); // 413
  console.log(details.context.responseText); // ""
});

darrachequesne avatar Aug 23 '24 21:08 darrachequesne

I think this can be closed now. Please reopen if needed.

darrachequesne avatar Sep 18 '24 10:09 darrachequesne

Tanks for your answer, but when i listen 'disconnect' event, i only get detail message is

 {
   "description": "websocket connection closed",
   "context": {
     "isTrusted":true
   }
}

Only listen 'error' message can get the 413 error, But need to reconnect several times to get the corresponding error。

{
 "description":413,
 "context":{},
 "type":"TransportError"
}

shuntian avatar Nov 01 '24 10:11 shuntian