From a610fa024fd977d96c09bd34dc02520ae3c9a6d5 Mon Sep 17 00:00:00 2001 From: koudle Date: Fri, 30 Nov 2018 01:31:57 +0800 Subject: [PATCH] fix crash when could not find package --- example/src/examples/cow_repository.dart | 9 ++++++--- .../src/examples/http_proxy_repository.dart | 20 +++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/example/src/examples/cow_repository.dart b/example/src/examples/cow_repository.dart index 4d86b5b..9e559ed 100644 --- a/example/src/examples/cow_repository.dart +++ b/example/src/examples/cow_repository.dart @@ -132,9 +132,12 @@ class _RemoteMetadataCache { var c = new Completer>(); _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; diff --git a/example/src/examples/http_proxy_repository.dart b/example/src/examples/http_proxy_repository.dart index 844e273..cd00c18 100644 --- a/example/src/examples/http_proxy_repository.dart +++ b/example/src/examples/http_proxy_repository.dart @@ -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; - 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; + 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; } }