isReconnectable property

bool get isReconnectable

Whether a connection closed for this reason is worth opening again.

Necessary but not sufficient: ConnectionRecoveryHandler reopens only a connection that was established, and only while the network and the app lifecycle allow it.

Implementation

bool get isReconnectable => switch (this) {
  UserInitiated() => false,
  // Credentials that could not be produced or sent will not fare better on
  // a retry — unless what stopped them was the network itself, which is
  // about the moment, not the credentials.
  AuthenticationFailed(:final error) => switch (error) {
    StreamNetworkException(isCancelled: true) => false,
    StreamNetworkException() => true,
    _ => false,
  },
  SystemInitiated() => true,
  UnHealthyConnection() => true,
  ConnectTimeout() => true,
  ServerInitiated(:final error) => switch (error) {
    StreamApiException(unrecoverable: true) => false,
    StreamApiException(isTokenSignatureInvalid: true) => false,
    StreamApiException(isApiKeyInvalid: true) => false,
    StreamApiException(isTokenExpired: true) => true,
    StreamApiException(isTokenNotYetValid: true) => true,
    StreamApiException(isRateLimited: true) => true,
    StreamApiException(:final statusCode) => statusCode < 400 || statusCode >= 500,
    StreamNetworkException(closeCode: CloseCode.normalClosure) => false,
    StreamNetworkException() => true,
    StreamAuthenticationException() => false,
    StreamClientException() => true,
    null => true,
  },
};