-
Notifications
You must be signed in to change notification settings - Fork 262
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Which middleware is the feature for?
@hono/node-ws
What is the feature you are proposing?
There are multiple cases where a custom HttpException thrown in upgradeWebSocket method would make sense, in particular throwing an HTTP 401 for Unauthorized requests.
Currently, when using @hono/node-ws, no matter which HttpException is thrown, the Websocket will be closed with HTTP 400 (as seen here: https://github.com/honojs/middleware/blob/main/packages/node-ws/src/index.ts#L85)
For example:
app.get(
"/ws",
upgradeWebSocket(async (c) => {
if (!isAuthorized(c.user)) {
throw new HTTPException(401, { message: "Unauthorized" });
}
...
}
)The expected result is to receive HTTP/1.1 401 Unauthorized response, but the actual result is: HTTP/1.1 400 Bad Request
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request