Skip to content

Commit 6caf3ed

Browse files
committed
Modified getReleaseByTagName to thrown an exception if the release can't be found.
1 parent dfe06d7 commit 6caf3ed

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

lib/src/common/repos_service.dart

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -968,30 +968,22 @@ class RepositoriesService extends Service {
968968

969969
/// Fetches a single release by the release tag name.
970970
///
971-
/// Returns null if the release doesn't exist.
971+
/// Throws a [ReleaseNotFound] exception if the release
972+
/// doesn't exist.
972973
///
973974
/// API docs: https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name
974975
Future<Release> getReleaseByTagName(
975976
RepositorySlug slug, String tagName) async {
976-
// github.getJSON('/repos/${slug.fullName}/releases/tags/$tagName', convert: (i) => Release.fromJson(i));
977-
978-
Release release;
979-
try {
980-
release = await github.getJSON(
981-
'/repos/${slug.fullName}/releases/tags/$tagName',
982-
convert: (i) => Release.fromJson(i),
983-
statusCode: StatusCodes.OK,
984-
fail: (http.Response response) {
985-
if (response.statusCode == 404) {
986-
// we just return null if the tag can't be found.
987-
throw ReleaseNotFound.fromTagName(github, tagName);
988-
}
989-
},
990-
);
991-
} on ReleaseNotFound catch (e) {
992-
release = null;
993-
}
994-
return release;
977+
return github.getJSON(
978+
'/repos/${slug.fullName}/releases/tags/$tagName',
979+
convert: (i) => Release.fromJson(i),
980+
statusCode: StatusCodes.OK,
981+
fail: (http.Response response) {
982+
if (response.statusCode == 404) {
983+
throw ReleaseNotFound.fromTagName(github, tagName);
984+
}
985+
},
986+
);
995987
}
996988

997989
/// Creates a Release based on the specified [createRelease].

0 commit comments

Comments
 (0)