safeCall<T> method
Executes request and maps any thrown error to an Err via the
registry. See SimpleNetworkHandler.safeCall for the historical docs;
semantics are identical.
Implementation
@override
Future<Result<T>> safeCall<T>(
Future<T> Function() request, {
Result<T>? Function(DioException)? onEndpointError,
}) async {
callCount++;
final next = _queue.isNotEmpty ? _queue.removeAt(0) : defaultResult;
if (next == null) {
throw StateError(
'FakeNetworkHandler: no queued result for call #$callCount. '
'Call enqueueOk/enqueueErr before exercising the code under test, '
'or set defaultResult.',
);
}
return next.fold((failure) => Err<T>(failure), (value) => Ok<T>(value as T));
}