safeApiCall<T> function
Implementation
Future<Either<NetworkException, T>> safeApiCall<T>(Function call,
{Map<String, dynamic>? params}) async {
try {
var result = params == null ? await call() : await call(params);
return Right(result);
} catch (e) {
if (e is NetworkException) {
return Left(e.handleNetworkException());
} else if (e is HandshakeException || e is SocketException) {
return Left(NoServerConnection());
} else {
return Left(
UnknownException(message: 'Ocorreu um erro', isRetryAble: false),
);
}
}
}