From ca0e7dd3d31680d6352a0e0829cde6ced8a6f0dd Mon Sep 17 00:00:00 2001 From: uKaigo <37600692+uKaigo@users.noreply.github.com> Date: Mon, 10 May 2021 09:36:04 -0300 Subject: [PATCH] Describe NoResults errors --- ksoftapi/__init__.py | 4 ++-- ksoftapi/apis/bans.py | 4 ++-- ksoftapi/apis/images.py | 8 ++++---- ksoftapi/apis/kumo.py | 4 ++-- ksoftapi/apis/music.py | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ksoftapi/__init__.py b/ksoftapi/__init__.py index f07183a..92f2551 100644 --- a/ksoftapi/__init__.py +++ b/ksoftapi/__init__.py @@ -8,7 +8,7 @@ __author__ = 'AndyTempel' __license__ = 'GNU' __copyright__ = 'Copyright 2018-2020 AndyTempel' -__version__ = '0.4.1' +__version__ = '0.4.2a' import logging from collections import namedtuple @@ -19,7 +19,7 @@ VersionInfo = namedtuple('VersionInfo', 'major minor micro releaselevel serial') -version_info = VersionInfo(major=0, minor=4, micro=1, releaselevel='alpha', serial=0) +version_info = VersionInfo(major=0, minor=4, micro=2, releaselevel='alpha', serial=0) try: from logging import NullHandler diff --git a/ksoftapi/apis/bans.py b/ksoftapi/apis/bans.py index 82bf3b4..2b52e02 100644 --- a/ksoftapi/apis/bans.py +++ b/ksoftapi/apis/bans.py @@ -122,8 +122,8 @@ async def info(self, user_id: int) -> BanInfo: """ r = await self._client.http.get('/bans/info', params={'user': user_id}) - if 'code' in r and r['code'] == 404: - raise NoResults + if r.get('code', 200) == 404: + raise NoResults(r['message']) return BanInfo(r) diff --git a/ksoftapi/apis/images.py b/ksoftapi/apis/images.py index e7c67fe..93729b1 100644 --- a/ksoftapi/apis/images.py +++ b/ksoftapi/apis/images.py @@ -28,7 +28,7 @@ async def random_image(self, tag: str, nsfw: bool = False) -> Image: r = await self._client.http.get('/images/random-image', params={'tag': tag, 'nsfw': nsfw}) if r.get('code', 200) == 404: - raise NoResults + raise NoResults(r['message']) return Image(r) @@ -92,7 +92,7 @@ async def random_reddit(self, subreddit: str, remove_nsfw: bool = False, span: s params={'remove_nsfw': remove_nsfw, 'span': span}) if r.get('code', 200) == 404: - raise NoResults + raise NoResults(r['message']) return RedditImage(r) @@ -123,7 +123,7 @@ async def get_image(self, snowflake: str) -> Image: r = await self._client.http.get('/images/image/{}'.format(snowflake)) if r.get('code', 200) == 404: - raise NoResults + raise NoResults(r['message']) return Image(r) @@ -143,7 +143,7 @@ async def search_tags(self, search: str) -> TagCollection: r = await self._client.http.get('/images/tags/{}'.format(search)) if r.get('code', 200) == 404: - raise NoResults + raise NoResults(r['message']) return TagCollection(r) diff --git a/ksoftapi/apis/kumo.py b/ksoftapi/apis/kumo.py index 846a32b..b25480c 100644 --- a/ksoftapi/apis/kumo.py +++ b/ksoftapi/apis/kumo.py @@ -39,7 +39,7 @@ async def gis(self, location: str, fast: bool = False, more: bool = False, map_z 'include_map': include_map}) if r.get('code', 200) == 404: - raise NoResults + raise NoResults(r['message']) result = r['data'] if isinstance(result, list): @@ -67,7 +67,7 @@ async def geoip(self, ip: str): r = await self._client.http.get('/kumo/geoip', params={'ip': ip}) if r.get('code', 200) == 404: - raise NoResults + raise NoResults(r['message']) result = r['data'] return IPInfo(result) diff --git a/ksoftapi/apis/music.py b/ksoftapi/apis/music.py index b33ff6d..a8dbae5 100644 --- a/ksoftapi/apis/music.py +++ b/ksoftapi/apis/music.py @@ -38,7 +38,7 @@ async def lyrics(self, query: str, text_only: bool = False, clean_up: bool = Tru results = r['data'] if not results: - raise NoResults + raise NoResults('Song not found.') return [LyricResult(lr) for lr in results] @@ -82,6 +82,6 @@ async def recommendations(self, tracks: list, provider: str, youtube_token: str results = r['tracks'] if not results: - raise NoResults + raise NoResults('No recommendations.') return [Recommendation(r) for r in results]