error handling in dictionary

This commit is contained in:
Will McGugan
2023-02-18 18:01:25 +00:00
parent b6272a3b59
commit 665efa2d05

View File

@@ -42,10 +42,11 @@ class DictionaryApp(App):
url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{word}"
async with httpx.AsyncClient() as client:
response = await client.get(url)
if response.status_code % 100 != 2:
try:
results = response.json()
except Exception:
self.query_one("#results", Static).update(response.text)
return
results = response.json()
if word == self.query_one(Input).value:
markdown = self.make_word_markdown(results)