getDioException static method
String
getDioException(
- dynamic error
)
Implementation
static String getDioException(error) {
if (error is Exception) {
try {
NetworkExceptions networkExceptions;
if (error is DioError) {
switch (error.type) {
case DioErrorType.cancel:
networkExceptions = const NetworkExceptions.requestCancelled();
break;
case DioErrorType.connectTimeout:
networkExceptions = const NetworkExceptions.requestTimeout();
break;
case DioErrorType.other:
networkExceptions =
const NetworkExceptions.noInternetConnection();
break;
case DioErrorType.receiveTimeout:
networkExceptions = const NetworkExceptions.sendTimeout();
break;
case DioErrorType.response:
networkExceptions =
NetworkExceptions.handleResponse(error.response?.statusCode);
break;
case DioErrorType.sendTimeout:
networkExceptions = const NetworkExceptions.sendTimeout();
break;
}
} else if (error is SocketException) {
networkExceptions = const NetworkExceptions.noInternetConnection();
} else {
networkExceptions = const NetworkExceptions.unexpectedError();
}
return getErrorMessage(networkExceptions);
// return networkExceptions;
} on FormatException {
// Helper.printError(e.toString());
return getErrorMessage(const NetworkExceptions.formatException());
} catch (_) {
return getErrorMessage(const NetworkExceptions.unexpectedError());
}
} else {
if (error.toString().contains("is not a subtype of")) {
return getErrorMessage(const NetworkExceptions.unableToProcess());
} else {
return getErrorMessage(const NetworkExceptions.unexpectedError());
}
}
}