trackHttpCall<T> method
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;
}
}