uNetworking/uWebSockets.js

How to refuse upgrade and handle the error client side ?

Sceat opened this issue · 4 comments

Sceat commented

I don't see a way to retrieve a cause on the client before the socket was opened.

Server:

App().ws('/*', {
  upgrade: (response, request, context) => {
    response.end('User limit reached')
    // response.writeStatus('400 Limit reached')
  },
})

Client

image

writeStatus must come before end

e3dio commented

It's standard spec that the websocket client does not display information about the connection open error. If you want to send info about the close to client you need to open connection then immediately close it with code/reason

Sceat commented

writeStatus must come before end

I tried both

It's standard spec that the websocket client does not display information about the connection open error. If you want to send info about the close to client you need to open connection then immediately close it with code/reason

Alright I see so we can't optimize that 👍🏻

Ah. Yeah just let the connection open and immediately close it. That is not more costly, anyways and you get a standard way of delivering standard error codes and reason to the client.