private async Task <Stream> TryDownloadPackage(IUpstreamNuGetSource source, string id, NuGetVersion version, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(Stream.Null); } try { return(await source.Client.DownloadPackageAsync(id, version, cancellationToken)); } catch (PackageNotFoundException) { _logger.LogWarning( $"Failed to download package {id} {version} from {source.Name}"); return(Stream.Null); } catch (Exception ex) { _logger.LogError( ex, $"Failed to mirror package {id} {version} from {source.Name}"); return(Stream.Null); } }
private async Task <T> RunOrNull <T>(IUpstreamNuGetSource source, string id, string data, Func <NuGetClient, Task <T> > func) where T : class { try { return(await func(source.Client)); } catch (Exception e) { _logger.LogError(e, $"Unable to mirror package {id}'s upstream {data} from {source.Name}"); return(null); } }