TF-196 Implement RemoteExceptionThrower when get session

This commit is contained in:
dab246
2022-06-22 11:26:43 +07:00
committed by Dat H. Pham
parent fd9b7cbb0a
commit 4cff46623c
12 changed files with 117 additions and 27 deletions
@@ -5,9 +5,20 @@ 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);
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(exception.toString());
throw UnknownError(message: exception.toString());
}
}
}