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
@@ -1,19 +1,34 @@
import 'package:core/data/network/remote_exception_thrower.dart';
import 'package:core/domain/exceptions/remote_exception.dart';
import 'package:core/utils/app_logger.dart';
import 'package:dio/dio.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
import 'package:tmail_ui_user/features/session/data/datasource/session_datasource.dart';
import 'package:tmail_ui_user/features/session/data/network/session_api.dart';
class SessionDataSourceImpl extends SessionDataSource {
final SessionAPI sessionAPI;
final SessionAPI _sessionAPI;
final RemoteExceptionThrower _remoteExceptionThrower;
SessionDataSourceImpl(this.sessionAPI);
SessionDataSourceImpl(this._sessionAPI, this._remoteExceptionThrower);
@override
Future<Session> getSession() {
return Future.sync(() async {
return await sessionAPI.getSession();
return await _sessionAPI.getSession();
}).catchError((error) {
throw error;
_remoteExceptionThrower.throwRemoteException(error, handler: (DioError error) {
if (error.response?.statusCode == 502) {
throw BadGateway();
} else {
log('SessionDataSourceImpl::getSession(): statusMessage: ${error.response?.statusMessage}');
throw UnknownError(
code: error.response?.statusCode,
message: error.response?.statusMessage);
}
});
});
}
}