Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
fix crash when could not find package
Browse files Browse the repository at this point in the history
  • Loading branch information
koudle committed Nov 29, 2018
1 parent a04463e commit a610fa0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
9 changes: 6 additions & 3 deletions example/src/examples/cow_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ class _RemoteMetadataCache {
var c = new Completer<Set<PackageVersion>>();

_versions.putIfAbsent(package, () => new Set());
remote.versions(package).toList().then((versions) {
_versions[package].addAll(versions);
c.complete(_versions[package]);
remote.versions(package)
.where((v) => v != null)
.toList()
.then((versions) {
_versions[package].addAll(versions);
c.complete(_versions[package]);
});

return c;
Expand Down
20 changes: 12 additions & 8 deletions example/src/examples/http_proxy_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ class HttpProxyRepository extends PackageRepository {
baseUrl.resolve('/api/packages/${Uri.encodeComponent(package)}');

http.Response response = await client.get(versionUrl);
var json = convert.json.decode(response.body);
var versions = json['versions'] as List<dynamic>;
if (versions != null) {
for (var item in versions) {
var pubspec = item['pubspec'];
var pubspecString = convert.json.encode(pubspec);
yield new PackageVersion(pubspec['name'] as String,
pubspec['version'] as String, pubspecString);
if(response.statusCode == 200) {
var json = convert.json.decode(response.body);
var versions = json['versions'] as List<dynamic>;
if (versions != null) {
for (var item in versions) {
var pubspec = item['pubspec'];
var pubspecString = convert.json.encode(pubspec);
yield new PackageVersion(pubspec['name'] as String,
pubspec['version'] as String, pubspecString);
}
}
}else{
yield null;
}
}

Expand Down

0 comments on commit a610fa0

Please sign in to comment.