classifyConnectionFailure function
What error says about the connection, or null when it says nothing:
a key that was not found, a value that failed to parse, a privilege the
enrollment lacks all mean the atServer answered, and the classification
for those is AtConnectionState.online, while an error about the caller's
own arguments says nothing at all.
at_lookup's executeVerb throws an atServer's error: reply to the verb
as an AtLookUpException carrying the code the reply names, or AT0014
when it names none, and wraps every other failure as one carrying a code,
with the failure as its cause: an AtLookUpException's own code, such as
a proxy's error: reply to its from:, or else the code error_codes
has for the exception's type, or AT0014 for a type it has none for. An
UnAuthenticatedException raised by the authenticator is wrapped as
AT0401 and read as its cause, whose
AtAuthErrorReplyException.errorCode is the atServer's own code.
No code is read out of a message's text.
Implementation
AtConnectionState? classifyConnectionFailure(Object error) {
if (error is AtLookUpException) {
final cause = error.cause;
if (cause is UnAuthenticatedException) {
return _classifyAuthentication(cause.message, _replyCode(cause), error);
}
return _classifyCode(error.errorCode, error.errorMessage, error);
}
if (error is UnAuthenticatedException) {
return _classifyAuthentication(error.message, _replyCode(error), error);
}
if (error is AtInvalidEnrollmentException) {
return AtConnectionState.refused(AtConnectionCause.invalidEnrollment,
error: error);
}
if (error is SecondaryNotFoundException) {
return AtConnectionState.offline(AtConnectionCause.noAtServer,
error: error);
}
if (error is UnAuthorizedException) {
return AtConnectionState.online();
}
if (error is AtConnectException ||
error is SecondaryConnectException ||
error is AtTimeoutException ||
error is AtIOException ||
error is TimeoutException) {
return AtConnectionState.offline(AtConnectionCause.unreachable,
error: error);
}
if (error is AtException && _readsUnreachable(error.message)) {
return AtConnectionState.offline(AtConnectionCause.unreachable,
error: error);
}
return null;
}