Skip to content

Commit 79015a5

Browse files
committed
Fix parse_creator() to handle user not found edge-case
Fixes #50
1 parent af24d20 commit 79015a5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

redgifs/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from typing import TYPE_CHECKING
3030

3131
from .enums import MediaType
32+
from .errors import RedGifsError
3233
from .utils import _users_iter, build_file_url, to_embed_url, to_web_url
3334
from .models import GIF, URL, CreatorResult, Image, User, SearchResult, CreatorsResult
3435

@@ -195,6 +196,12 @@ def parse_creators(json: CreatorsResponse) -> CreatorsResult:
195196

196197
def parse_creator(json: CreatorResponse, media_type: MediaType) -> CreatorResult:
197198
_log.debug('Using `parse_creator`')
199+
200+
# RedGifs API should actually throw a 404 HTTP response if the user is not found
201+
# BUT since it does NOT do that everytime, this is how we are going to handle it.
202+
if len(json['users']) == 0:
203+
raise RedGifsError('User not found')
204+
198205
user = json['users'][0]
199206
return CreatorResult(
200207
creator=User(

0 commit comments

Comments
 (0)