isReconnectable property
bool
get
isReconnectable
Whether a connection closed for this reason is worth opening again.
- SystemInitiated, UnHealthyConnection, ConnectTimeout — yes.
- UserInitiated — no.
- AuthenticationFailed — only for a StreamNetworkException that is not StreamNetworkException.isCancelled.
- ServerInitiated — decided by the error it carries. No for a StreamApiException that is StreamApiException.unrecoverable, reports a refused token signature or API key, or carries any other 4xx; no for a StreamNetworkException closing with CloseCode.normalClosure; no for a StreamAuthenticationException. Yes for anything else, including an expired or not-yet-valid token, a rate limit, a 5xx, and no error at all.
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,
},
};