parsedArriRequest<T, E extends Exception> function

Future<T> parsedArriRequest<T, E extends Exception>(
  1. String url, {
  2. Client? httpClient,
  3. HttpMethod method = HttpMethod.post,
  4. Map<String, dynamic>? params,
  5. FutureOr<Map<String, String>> headers()?,
  6. Duration? timeout,
  7. dynamic onError(
    1. Object
    )?,
  8. String? clientVersion,
  9. required T parser(
    1. String
    ),
})

Helper function for performing raw HTTP request to an Arri RPC server This function will throw an ArriRequestError if it fails

Implementation

Future<T> parsedArriRequest<T, E extends Exception>(
  String url, {
  http.Client? httpClient,
  HttpMethod method = HttpMethod.post,
  Map<String, dynamic>? params,
  FutureOr<Map<String, String>> Function()? headers,
  Duration? timeout,
  Function(Object)? onError,
  String? clientVersion,
  required T Function(String) parser,
}) async {
  final http.Response result;

  try {
    result = await arriRequest(
      url,
      httpClient: httpClient,
      method: method,
      params: params,
      headers: headers,
      clientVersion: clientVersion,
      timeout: timeout,
    );
    if (result.statusCode >= 200 && result.statusCode <= 299) {
      return parser(utf8.decode(result.bodyBytes));
    }
  } catch (err) {
    onError?.call(err);
    rethrow;
  }
  final err = ArriError.fromResponse(result);
  onError?.call(err);
  throw err;
}