dioExceptionTypeOf function
The DioExceptionType that best describes error.
Exhaustive over the sealed nh.NitroHttpException hierarchy, so a new
failure kind in nitro_http breaks this switch instead of silently
arriving as DioExceptionType.unknown.
Implementation
DioExceptionType dioExceptionTypeOf(nh.NitroHttpException error) =>
switch (error) {
nh.NitroHttpTimeoutException(:final stage) => switch (stage) {
// The engine has one deadline for the whole transfer, so a request or
// idle timeout is reported as dio's receive timeout. dio's
// `sendTimeout` is never produced here — see the README.
nh.TimeoutStage.connect => DioExceptionType.connectionTimeout,
nh.TimeoutStage.request ||
nh.TimeoutStage.idle => DioExceptionType.receiveTimeout,
},
nh.NitroHttpCancelException() => DioExceptionType.cancel,
// dio has one TLS bucket, so a rejected chain and a handshake that never
// produced one share it; a refused configuration is not a transport
// fault at all and stays `unknown`.
nh.NitroHttpCertificateException() ||
nh.NitroHttpTlsException() => DioExceptionType.badCertificate,
nh.NitroHttpConfigurationException() => DioExceptionType.unknown,
nh.NitroHttpConnectionException() => DioExceptionType.connectionError,
// Only reachable through a borrowed client left on
// `throwOnStatusCode: true`; an adapter-owned client never throws these.
nh.NitroHttpStatusCodeException() => DioExceptionType.badResponse,
nh.NitroHttpRedirectException() ||
nh.NitroHttpProtocolException() ||
nh.NitroHttpDecodingException() ||
// dio has no size-limit bucket, and `badResponse` would leave a consumer
// reading a `response` that was never delivered.
nh.NitroHttpResponseTooLargeException() ||
nh.NitroHttpCacheMissException() ||
nh.NitroHttpDisposedException() ||
nh.NitroHttpUnknownException() => DioExceptionType.unknown,
};