fetch method
Returns a ResponseBody
matching the request if one exists in charlatan.
If no response matches, throws UnimplementedError.
Implementation
@override
Future<ResponseBody> fetch(
RequestOptions options,
Stream<Uint8List>? requestStream,
Future? cancelFuture,
) async {
final path = options.path;
final method = options.method.toLowerCase();
final request = CharlatanHttpRequest(
requestOptions: options,
);
final match = charlatan.findMatch(request);
if (match != null) {
return _buildResponse(request, match);
}
final errorMessage = '''
Unable to find matching fake http response definition for:
${method.toUpperCase()} $path
Did you configure it?
The fake http response definitions configured were:
${charlatan.toPrettyPrintedString()}
''';
if (charlatan.shouldLogErrors) {
// ignore: avoid_print
print(errorMessage);
}
throw UnimplementedError(errorMessage);
}