classifyError static method

String classifyError(
  1. Object error
)

Classifies a transport/HTTP failure into a catalog http.error.category.

Client-specific errors (for example Dio) should be classified by the owning integration and passed to onError as errorCategory.

Implementation

static String classifyError(Object error) {
  if (error is TimeoutException) return 'timeout';
  if (error is HandshakeException || error is TlsException) return 'ssl';
  if (error is SocketException) {
    final msg = error.message.toLowerCase();
    final os = error.osError?.message.toLowerCase() ?? '';
    if (msg.contains('failed host lookup') ||
        msg.contains('name or service not known') ||
        os.contains('failed host lookup') ||
        os.contains('nodename nor servname')) {
      return 'dns';
    }
    return 'io';
  }
  if (error is IOException) return 'io';
  return 'unknown';
}