Skip to content

Commit

Permalink
Handle 404 errors in fetch_stories #949
Browse files Browse the repository at this point in the history
  • Loading branch information
dostogircse171 committed Feb 18, 2024
1 parent b919fe6 commit dd15e17
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions story/management/commands/fetch_stories.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ def handle(self, *args, **options):
story = Story(name=name, post_url=post_url, content=_post, is_story=is_story)

if image_url:
img = NamedTemporaryFile(delete=True)
img.write(urlopen(image_url).read())
img.flush()
story.image.save(image_url.split("/")[-1], File(img))
try:
with NamedTemporaryFile(delete=True) as img:
img.write(urlopen(image_url).read())
img.flush()
story.image.save(image_url.split("/")[-1], File(img))
except Exception as e:
print(f"Failed to fetch image from {image_url}: {e}")

story.save()

Expand Down

0 comments on commit dd15e17

Please sign in to comment.