execute<T> method

Future<T> execute<T>(
  1. Future callback(), {
  2. AlgodTransformer<dynamic, T>? transformer,
})

Implementation

Future<T> execute<T>(
  Future<dynamic> Function() callback, {
  AlgodTransformer<dynamic, T>? transformer,
}) async {
  try {
    final response = await callback();
    if (transformer != null) {
      return transformer.transform(response);
    }

    if (response is! T) {
      throw AlgorandException(message: 'Response does not match');
    }

    return response;
  } on DioError catch (ex) {
    throw AlgorandException.fromDioError(ex);
  }
}