trackHttpCall<T> method

Future<T> trackHttpCall<T>(
  1. String url,
  2. Future<T> call(), {
  3. String method = 'GET',
  4. int extractStatusCode(
    1. T response
    )?,
})

Convenience wrapper that tracks an asynchronous HTTP call.

extractStatusCode converts the response object to a status code. If omitted, a successful call is recorded as 200.

Implementation

Future<T> trackHttpCall<T>(
  String url,
  Future<T> Function() call, {
  String method = 'GET',
  int Function(T response)? extractStatusCode,
}) async {
  final record = trackRequest(url, method: method);
  try {
    final result = await call();
    final code = extractStatusCode != null ? extractStatusCode(result) : 200;
    completeRequest(record, statusCode: code);
    return result;
  } catch (_) {
    completeRequest(record, statusCode: 0);
    rethrow;
  }
}