From 665efa2d052b837fc4986e3931eee0b849bc3f1e Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 18 Feb 2023 18:01:25 +0000 Subject: [PATCH] error handling in dictionary --- examples/dictionary.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/dictionary.py b/examples/dictionary.py index 04183170c..8ef47f3bb 100644 --- a/examples/dictionary.py +++ b/examples/dictionary.py @@ -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)