TF-196 Create RemoteExceptionThrower to catch error from network

This commit is contained in:
dab246
2022-06-21 16:10:56 +07:00
committed by Dat H. Pham
parent ea6a4aff9f
commit fd9b7cbb0a
3 changed files with 31 additions and 0 deletions
+2
View File
@@ -14,6 +14,8 @@ export 'domain/extensions/media_type_extension.dart';
// Exceptions
export 'domain/exceptions/download_file_exception.dart';
export 'data/extensions/options_extensions.dart';
export 'domain/exceptions/remote_exception.dart';
export 'data/network/remote_exception_thrower.dart';
// Utils
export 'presentation/utils/theme_utils.dart';
@@ -0,0 +1,13 @@
import 'package:core/domain/exceptions/remote_exception.dart';
import 'package:dio/dio.dart';
class RemoteExceptionThrower {
void throwRemoteException(dynamic exception, {Function(DioError)? handler}) {
if (exception is DioError) {
handler != null ? handler(exception) : throw UnknownError(exception.message);
} else {
throw UnknownError(exception.toString());
}
}
}
@@ -0,0 +1,16 @@
import 'package:equatable/equatable.dart';
abstract class RemoteException extends Equatable implements Exception {
final String? message;
RemoteException(this.message);
}
class UnknownError extends RemoteException {
UnknownError(String? message) : super(message);
@override
List<Object> get props => [];
}