Skip to content

Commit

Permalink
Merge pull request #19 from uKaigo/add/missing-errors
Browse files Browse the repository at this point in the history
Add checks for code 125 and 130 in random_reddit
  • Loading branch information
AndyTempel authored May 12, 2021
2 parents 2bf8567 + ff9a924 commit f60d1d0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ksoftapi/apis/bans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 r.get('code', 200) == 404:
raise NoResults(r['message'])
if 'code' in r and r['code'] == 404:
raise NoResults

return BanInfo(r)

Expand Down
15 changes: 9 additions & 6 deletions ksoftapi/apis/images.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..errors import NoResults
from ..errors import NoResults, BadRequest
from ..models import Image, RedditImage, TagCollection, WikiHowImage


Expand Down Expand Up @@ -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(r['message'])
raise NoResults

return Image(r)

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

if r.get('code', 200) == 404:
raise NoResults(r['message'])
if r.get('code', 200) == 125:
raise BadRequest(r['message'])

if r.get('code', 200) in (404, 130):
raise NoResults

return RedditImage(r)

Expand Down Expand Up @@ -123,7 +126,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(r['message'])
raise NoResults

return Image(r)

Expand All @@ -143,7 +146,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(r['message'])
raise NoResults

return TagCollection(r)

Expand Down
4 changes: 2 additions & 2 deletions ksoftapi/apis/kumo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(r['message'])
raise NoResults

result = r['data']
if isinstance(result, list):
Expand Down Expand Up @@ -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(r['message'])
raise NoResults

result = r['data']
return IPInfo(result)
Expand Down
4 changes: 2 additions & 2 deletions ksoftapi/apis/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('Song not found.')
raise NoResults

return [LyricResult(lr) for lr in results]

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

if not results:
raise NoResults('No recommendations.')
raise NoResults

return [Recommendation(r) for r in results]
4 changes: 4 additions & 0 deletions ksoftapi/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
class BadRequest(Exception):
pass


class NoResults(Exception):
pass

Expand Down

0 comments on commit f60d1d0

Please sign in to comment.