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
@@ -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());
}
}
}