TF-196 Create RemoteExceptionThrower to catch error from network
This commit is contained in:
@@ -14,6 +14,8 @@ export 'domain/extensions/media_type_extension.dart';
|
|||||||
// Exceptions
|
// Exceptions
|
||||||
export 'domain/exceptions/download_file_exception.dart';
|
export 'domain/exceptions/download_file_exception.dart';
|
||||||
export 'data/extensions/options_extensions.dart';
|
export 'data/extensions/options_extensions.dart';
|
||||||
|
export 'domain/exceptions/remote_exception.dart';
|
||||||
|
export 'data/network/remote_exception_thrower.dart';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
export 'presentation/utils/theme_utils.dart';
|
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 => [];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user