You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actual behavior (the bug)
An error occurring inside of a wsBeforeUpgrade(...) handler, eg: authenticating requests before upgrading to a websocket resulting in an UnauthorizedResponse being thrown, results in no RequestLogger method being invoked.
Expected behavior
As the HTTP Request has not be upgraded to a WebSocket yet, I would expect the RequestLogger.handle(@NotNull Context ctx, @NotNull Float executionTimeMs) throws Exception method to be invoked.
I would not expect the WebSocket Request Logger to be executed, as the HTTP Request is not an Upgraded Request yet.
Register your WebSocket endpoints and wsBeforeUpgrade handler:
javalin.wsBeforeUpgrade("/ws", ctx -> {
thrownewUnauthorizedResponse();
});
// Required otherwise the wsBeforeUpgrade doesn't match anything.javalin.ws("/ctx", wsConfig -> {});
Invoke a HTTP Upgrade Request to the /ws endpoint.
Observe that you get a 401 Unauthorized response.
Observe that nothing is no logged.
Additional context
You can hack around this by using Exception Handlers but if you have multiple exception handlers, or error types then this gets very messy and is not a great solution.
Actual behavior (the bug)
An error occurring inside of a
wsBeforeUpgrade(...)
handler, eg: authenticating requests before upgrading to a websocket resulting in anUnauthorizedResponse
being thrown, results in no RequestLogger method being invoked.Expected behavior
As the HTTP Request has not be upgraded to a WebSocket yet, I would expect the
RequestLogger.handle(@NotNull Context ctx, @NotNull Float executionTimeMs) throws Exception
method to be invoked.I would not expect the WebSocket Request Logger to be executed, as the HTTP Request is not an Upgraded Request yet.
To Reproduce
wsBeforeUpgrade
handler:/ws
endpoint.Additional context
You can hack around this by using Exception Handlers but if you have multiple exception handlers, or error types then this gets very messy and is not a great solution.
If you did this same pattern for HTTP requests:
then you get the following log output via the
RequestLogger.handle(...)
method:The text was updated successfully, but these errors were encountered: