call method

Future<HttpResponse> call(
  1. HttpRequest request
)

The transport function to hand to a client.

Implementation

Future<HttpResponse> call(HttpRequest request) async {
  requests.add(request);
  final index = requests.length - 1;

  final failure = throwOnAttempt[index];
  if (failure != null) throw failure;

  if (responses.isEmpty) {
    throw StateError('FakeTransport was given no responses');
  }
  return responses[index < responses.length ? index : responses.length - 1];
}