From aa2a25fffeff34b85a2d6b1f91d614b7566da1a6 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Mon, 14 Nov 2022 20:56:04 -0500 Subject: [PATCH] Better GitHub error messages (#112) --- lib/app_sources/github.dart | 30 ++++++++++++--------------- lib/mass_app_sources/githubstars.dart | 11 +++------- lib/providers/source_provider.dart | 6 ++++++ 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/app_sources/github.dart b/lib/app_sources/github.dart index 69bfa67..98ba2e8 100644 --- a/lib/app_sources/github.dart +++ b/lib/app_sources/github.dart @@ -167,14 +167,8 @@ class GitHub extends AppSource { } return APKDetails(version, targetRelease['apkUrls']); } else { - if (res.headers['x-ratelimit-remaining'] == '0') { - throw RateLimitError( - (int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') / - 60000000) - .round()); - } - - throw NoReleasesError(); + rateLimitErrorCheck(res); + throw getObtainiumHttpError(res); } } @@ -200,15 +194,17 @@ class GitHub extends AppSource { } return urlsWithDescriptions; } else { - if (res.headers['x-ratelimit-remaining'] == '0') { - throw RateLimitError( - (int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') / - 60000000) - .round()); - } - throw ObtainiumError( - res.reasonPhrase ?? 'Error ${res.statusCode.toString()}', - unexpected: true); + rateLimitErrorCheck(res); + throw getObtainiumHttpError(res); + } + } + + rateLimitErrorCheck(Response res) { + if (res.headers['x-ratelimit-remaining'] == '0') { + throw RateLimitError( + (int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') / + 60000000) + .round()); } } } diff --git a/lib/mass_app_sources/githubstars.dart b/lib/mass_app_sources/githubstars.dart index de85411..bc25621 100644 --- a/lib/mass_app_sources/githubstars.dart +++ b/lib/mass_app_sources/githubstars.dart @@ -27,14 +27,9 @@ class GitHubStars implements MassAppUrlSource { } return urlsWithDescriptions; } else { - if (res.headers['x-ratelimit-remaining'] == '0') { - throw RateLimitError( - (int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') / - 60000000) - .round()); - } - - throw ObtainiumError('Unable to find user\'s starred repos'); + var gh = GitHub(); + gh.rateLimitErrorCheck(res); + throw getObtainiumHttpError(res); } } diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index c39656f..1a2cee1 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:html/dom.dart'; +import 'package:http/http.dart'; import 'package:obtainium/app_sources/fdroid.dart'; import 'package:obtainium/app_sources/github.dart'; import 'package:obtainium/app_sources/gitlab.dart'; @@ -164,6 +165,11 @@ class AppSource { } } +ObtainiumError getObtainiumHttpError(Response res) { + return ObtainiumError( + res.reasonPhrase ?? 'Error ${res.statusCode.toString()}'); +} + abstract class MassAppUrlSource { late String name; late List requiredArgs;