executeFuture<T> method

FutureOr<T> executeFuture<T>({
  1. required Future<T> future(),
})

Implementation

FutureOr<T> executeFuture<T>({
  required Future<T> Function() future,
}) async {
  try {
    return await future();
  } on DioException catch (error) {
    const encoder = JsonEncoder.withIndent('  ');

    String? errorResponse;
    String? requestBody;

    try {
      errorResponse = encoder.convert(
        error.response?.data,
      );
    } catch (_) {
      errorResponse = 'Could not parse error';
    }

    try {
      requestBody = encoder.convert(error.requestOptions.data);
    } catch (_) {
      requestBody = 'Could not parse request body';
    }
    rethrow;
  } catch (error) {
    rethrow;
  }
}