TF-1115 Add RemoteExceptionThrower

This commit is contained in:
dab246
2022-10-27 16:59:31 +07:00
committed by Dat H. Pham
parent 1e855c26bc
commit fb177fb33d
14 changed files with 108 additions and 74 deletions
@@ -1,24 +0,0 @@
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) {
switch (exception.type) {
case DioErrorType.connectTimeout:
throw ConnectError();
default:
if (handler != null) {
throw handler(exception);
} else {
throw UnknownError(
code: exception.response?.statusCode,
message: exception.message);
}
}
} else {
throw UnknownError(message: exception.toString());
}
}
}