diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/CloseReason.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/CloseReason.java index 108c2d150b55b..009155eb67e41 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/CloseReason.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/CloseReason.java @@ -50,4 +50,9 @@ public String getMessage() { return message; } + @Override + public String toString() { + return "CloseReason [code=" + code + ", " + (message != null ? "message=" + message : "") + "]"; + } + } diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectionBase.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectionBase.java index 3b5694e9ac8c6..4febc7792d813 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectionBase.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectionBase.java @@ -131,7 +131,12 @@ public BroadcastSender broadcast() { public CloseReason closeReason() { WebSocketBase ws = webSocket(); if (ws.isClosed()) { - return new CloseReason(ws.closeStatusCode(), ws.closeReason()); + Short code = ws.closeStatusCode(); + if (code == null) { + // This could happen if the connection is terminated abruptly + return CloseReason.INTERNAL_SERVER_ERROR; + } + return new CloseReason(code, ws.closeReason()); } return null; }