static void closeSilently(
      final ServerWebSocket webSocket,
      final int code,
      final String message) {
    try {
      final ImmutableMap<String, String> finalMessage = ImmutableMap.of(
          "error",
          message != null ? message : ""
      );
      final String json = ApiJsonMapper.INSTANCE.get().writeValueAsString(finalMessage);
      webSocket
          .writeFinalTextFrame(json, r -> { })
          .close((short) code, truncate(message));
    } catch (final Exception e) {
      LOG.info("Exception caught closing websocket", e);
    }
  }
@Test
  public void shouldTruncateMessageLongerThanCloseReasonAllows() throws Exception {
    // Given:
    final String reason = "A long message that is longer than the maximum size that the "
        + "CloseReason class will allow-------------------------------------------------";
    assertThat("invalid test", reason.getBytes(UTF_8).length, greaterThan(123));

    // When:
    SessionUtil.closeSilently(websocket, INVALID_MESSAGE_TYPE.code(), reason);

    // Then:
    verify(websocket).writeFinalTextFrame(any(String.class), any(Handler.class));
    verify(websocket).close(codeCaptor.capture(), reasonCaptor.capture());
    assertThat(reasonCaptor.getValue(), is(
        "A long message that is longer than the maximum size that the CloseReason class "
            + "will allow-------------------------------..."));
    assertThat(reasonCaptor.getValue().getBytes(UTF_8).length,
        is(123));
  }