Skip to content

Commit

Permalink
error handling suggested by @coderabbitai
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 16, 2024
1 parent a894bcb commit 83771d8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import requests
from ovos_bus_client.message import Message
from ovos_workshop.decorators import intent_handler, resting_screen_handler
from ovos_utils.log import LOG
from ovos_workshop.decorators import intent_handler
from ovos_workshop.intents import IntentBuilder
from ovos_workshop.skills import OVOSSkill

Expand All @@ -12,8 +13,14 @@ def get_wallpapers(query: Optional[str] = None):
params = {"sorting": "random"}
if query:
params["q"] = query
data = requests.get(url, params=params).json()["data"]
return [w["path"] for w in data]
try:
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
data = response.json()["data"]
return [w["path"] for w in data]
except (requests.RequestException, KeyError, ValueError) as e:
LOG.error(f"Error fetching wallpapers: {str(e)}")
return []


class WallpapersSkill(OVOSSkill):
Expand Down

0 comments on commit 83771d8

Please sign in to comment.