getJayNetworkException static method
Implementation
static NetworkExceptions? getJayNetworkException(error) {
if (error is Exception) {
try {
NetworkExceptions? networkExceptions;
if (error is DioError) {
switch (error.type) {
case DioErrorType.cancel:
networkExceptions = NetworkExceptions.requestCancelled();
break;
case DioErrorType.connectTimeout:
networkExceptions = NetworkExceptions.requestTimeout();
break;
case DioErrorType.other:
networkExceptions = NetworkExceptions.noInternetConnection();
break;
case DioErrorType.receiveTimeout:
networkExceptions = NetworkExceptions.sendTimeout();
break;
case DioErrorType.response:
networkExceptions =
NetworkExceptions.handleResponse(error.response!);
break;
case DioErrorType.sendTimeout:
networkExceptions = NetworkExceptions.sendTimeout();
break;
}
} else if (error is SocketException) {
networkExceptions = NetworkExceptions.noInternetConnection();
} else if (error is TimeoutException) {
networkExceptions = NetworkExceptions.requestTimeout();
} else if (error is HttpException) {
networkExceptions = NetworkExceptions.notImplemented();
} else {
networkExceptions = NetworkExceptions.unexpectedError();
}
return networkExceptions;
} on FormatException catch (_) {
return NetworkExceptions.formatException();
} catch (e) {
return NetworkExceptions.unexpectedError();
}
} else {
if (error.toString().contains("is not a subtype of")) {
return NetworkExceptions.unableToProcess();
} else {
return NetworkExceptions.unexpectedError();
}
}
}