public static @NotNull @Nls String buildErrorMessage(@NotNull Throwable e) {
    Throwable unwrapped = RemoteUtil.unwrap(e);
    String reason = unwrapped.getLocalizedMessage();
    if (!StringUtil.isEmpty(reason)) {
      return reason;
    }
    else if (unwrapped.getClass() == ExternalSystemException.class) {
      String originalReason = ((ExternalSystemException)unwrapped).getOriginalReason();
      if (originalReason.isBlank()) {
        return stacktraceAsString(unwrapped);
      }
      return ExternalSystemBundle.message("external.system.api.error.message.prefix", originalReason);
    }
    else {
      return stacktraceAsString(unwrapped);
    }
  }
public static @NotNull @Nls String buildErrorMessage(@NotNull Throwable e)