Skip to content

Commit f60d1d0

Browse files
authored
Merge pull request #19 from uKaigo/add/missing-errors
Add checks for code 125 and 130 in random_reddit
2 parents 2bf8567 + ff9a924 commit f60d1d0

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

ksoftapi/apis/bans.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ async def info(self, user_id: int) -> BanInfo:
122122
"""
123123
r = await self._client.http.get('/bans/info', params={'user': user_id})
124124

125-
if r.get('code', 200) == 404:
126-
raise NoResults(r['message'])
125+
if 'code' in r and r['code'] == 404:
126+
raise NoResults
127127

128128
return BanInfo(r)
129129

ksoftapi/apis/images.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..errors import NoResults
1+
from ..errors import NoResults, BadRequest
22
from ..models import Image, RedditImage, TagCollection, WikiHowImage
33

44

@@ -28,7 +28,7 @@ async def random_image(self, tag: str, nsfw: bool = False) -> Image:
2828
r = await self._client.http.get('/images/random-image', params={'tag': tag, 'nsfw': nsfw})
2929

3030
if r.get('code', 200) == 404:
31-
raise NoResults(r['message'])
31+
raise NoResults
3232

3333
return Image(r)
3434

@@ -91,8 +91,11 @@ async def random_reddit(self, subreddit: str, remove_nsfw: bool = False, span: s
9191
r = await self._client.http.get('/images/rand-reddit/{}'.format(subreddit),
9292
params={'remove_nsfw': remove_nsfw, 'span': span})
9393

94-
if r.get('code', 200) == 404:
95-
raise NoResults(r['message'])
94+
if r.get('code', 200) == 125:
95+
raise BadRequest(r['message'])
96+
97+
if r.get('code', 200) in (404, 130):
98+
raise NoResults
9699

97100
return RedditImage(r)
98101

@@ -123,7 +126,7 @@ async def get_image(self, snowflake: str) -> Image:
123126
r = await self._client.http.get('/images/image/{}'.format(snowflake))
124127

125128
if r.get('code', 200) == 404:
126-
raise NoResults(r['message'])
129+
raise NoResults
127130

128131
return Image(r)
129132

@@ -143,7 +146,7 @@ async def search_tags(self, search: str) -> TagCollection:
143146
r = await self._client.http.get('/images/tags/{}'.format(search))
144147

145148
if r.get('code', 200) == 404:
146-
raise NoResults(r['message'])
149+
raise NoResults
147150

148151
return TagCollection(r)
149152

ksoftapi/apis/kumo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def gis(self, location: str, fast: bool = False, more: bool = False, map_z
3939
'include_map': include_map})
4040

4141
if r.get('code', 200) == 404:
42-
raise NoResults(r['message'])
42+
raise NoResults
4343

4444
result = r['data']
4545
if isinstance(result, list):
@@ -67,7 +67,7 @@ async def geoip(self, ip: str):
6767
r = await self._client.http.get('/kumo/geoip', params={'ip': ip})
6868

6969
if r.get('code', 200) == 404:
70-
raise NoResults(r['message'])
70+
raise NoResults
7171

7272
result = r['data']
7373
return IPInfo(result)

ksoftapi/apis/music.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def lyrics(self, query: str, text_only: bool = False, clean_up: bool = Tru
3838
results = r['data']
3939

4040
if not results:
41-
raise NoResults('Song not found.')
41+
raise NoResults
4242

4343
return [LyricResult(lr) for lr in results]
4444

@@ -82,6 +82,6 @@ async def recommendations(self, tracks: list, provider: str, youtube_token: str
8282
results = r['tracks']
8383

8484
if not results:
85-
raise NoResults('No recommendations.')
85+
raise NoResults
8686

8787
return [Recommendation(r) for r in results]

ksoftapi/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# -*- coding: utf-8 -*-
2+
class BadRequest(Exception):
3+
pass
4+
5+
26
class NoResults(Exception):
37
pass
48

0 commit comments

Comments
 (0)