[Android][Disable work manager] check internet connection directly
(cherry picked from commit de517af8cce44d34f01fc889c9b03c01ee489351)
This commit is contained in:
committed by
Dat H. Pham
parent
a4e9f21a4b
commit
cb50c183cf
@@ -96,4 +96,8 @@ class NetworkConnectionController extends GetxController {
|
||||
return _connectivityResult.value != ConnectivityResult.none &&
|
||||
_internetConnectionStatus.value == InternetConnectionStatus.connected;
|
||||
}
|
||||
|
||||
Future<bool> hasInternetConnection() {
|
||||
return _internetConnectionChecker.hasConnection;
|
||||
}
|
||||
}
|
||||
@@ -22,50 +22,54 @@ class RemoteExceptionThrower extends ExceptionThrower {
|
||||
logError('RemoteExceptionThrower::throwException():isNetworkConnectionAvailable');
|
||||
throw const NoNetworkError();
|
||||
} else {
|
||||
if (error is DioError) {
|
||||
logError('RemoteExceptionThrower::throwException():type: ${error.type} | response: ${error.response} | error: ${error.error}');
|
||||
if (error.response != null) {
|
||||
if (error.response!.statusCode == HttpStatus.internalServerError) {
|
||||
throw const InternalServerError();
|
||||
} else if (error.response!.statusCode == HttpStatus.badGateway) {
|
||||
throw BadGateway();
|
||||
} else if (error.response!.statusCode == HttpStatus.unauthorized) {
|
||||
throw const BadCredentialsException();
|
||||
} else {
|
||||
throw UnknownError(
|
||||
handleDioError(error);
|
||||
}
|
||||
}
|
||||
|
||||
void handleDioError(dynamic error) {
|
||||
if (error is DioError) {
|
||||
logError('RemoteExceptionThrower::throwException():type: ${error.type} | response: ${error.response} | error: ${error.error}');
|
||||
if (error.response != null) {
|
||||
if (error.response!.statusCode == HttpStatus.internalServerError) {
|
||||
throw const InternalServerError();
|
||||
} else if (error.response!.statusCode == HttpStatus.badGateway) {
|
||||
throw BadGateway();
|
||||
} else if (error.response!.statusCode == HttpStatus.unauthorized) {
|
||||
throw const BadCredentialsException();
|
||||
} else {
|
||||
throw UnknownError(
|
||||
code: error.response!.statusCode,
|
||||
message: error.response!.statusMessage);
|
||||
}
|
||||
} else {
|
||||
switch (error.type) {
|
||||
case DioErrorType.connectionTimeout:
|
||||
throw ConnectionTimeout(message: error.message);
|
||||
case DioErrorType.connectionError:
|
||||
throw ConnectionError(message: error.message);
|
||||
case DioErrorType.badResponse:
|
||||
throw const BadCredentialsException();
|
||||
default:
|
||||
if (error.error is SocketException) {
|
||||
throw const SocketError();
|
||||
} else if (error.error != null) {
|
||||
throw UnknownError(message: error.error!.toString());
|
||||
} else {
|
||||
throw const UnknownError();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (error is ErrorMethodResponseException) {
|
||||
final errorResponse = error.errorResponse as ErrorMethodResponse;
|
||||
if (errorResponse is CannotCalculateChangesMethodResponse) {
|
||||
throw CannotCalculateChangesMethodResponseException();
|
||||
} else {
|
||||
throw MethodLevelErrors(
|
||||
errorResponse.type,
|
||||
message: errorResponse.description);
|
||||
}
|
||||
} else {
|
||||
throw error;
|
||||
switch (error.type) {
|
||||
case DioErrorType.connectionTimeout:
|
||||
throw ConnectionTimeout(message: error.message);
|
||||
case DioErrorType.connectionError:
|
||||
throw ConnectionError(message: error.message);
|
||||
case DioErrorType.badResponse:
|
||||
throw const BadCredentialsException();
|
||||
default:
|
||||
if (error.error is SocketException) {
|
||||
throw const SocketError();
|
||||
} else if (error.error != null) {
|
||||
throw UnknownError(message: error.error!.toString());
|
||||
} else {
|
||||
throw const UnknownError();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (error is ErrorMethodResponseException) {
|
||||
final errorResponse = error.errorResponse as ErrorMethodResponse;
|
||||
if (errorResponse is CannotCalculateChangesMethodResponse) {
|
||||
throw CannotCalculateChangesMethodResponseException();
|
||||
} else {
|
||||
throw MethodLevelErrors(
|
||||
errorResponse.type,
|
||||
message: errorResponse.description);
|
||||
}
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:tmail_ui_user/features/network_connection/presentation/network_connection_controller.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
|
||||
|
||||
import '../routes/route_navigation.dart';
|
||||
|
||||
class SendEmailExceptionThrower extends RemoteExceptionThrower {
|
||||
@override
|
||||
FutureOr<void> throwException(error, stackTrace) async {
|
||||
log('SendEmailExceptionThrower::throwException(): $error | stackTrace: $stackTrace');
|
||||
final networkConnectionController = getBinding<NetworkConnectionController>();
|
||||
final realtimeNetworkConnectionStatus = await networkConnectionController?.hasInternetConnection();
|
||||
if (realtimeNetworkConnectionStatus == false) {
|
||||
logError('SendEmailExceptionThrower::throwException(): No realtime network connection');
|
||||
throw const NoNetworkError();
|
||||
} else {
|
||||
handleDioError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user