diff options
| author | 2021-08-08 15:51:44 +0200 | |
|---|---|---|
| committer | 2021-08-08 15:51:44 +0200 | |
| commit | ff0d3a833bbbe517f50124c5157223ff95876931 (patch) | |
| tree | a857bc79dcc672d01a907eab7381b25759c872fb /bot/exts/evergreen/wikipedia.py | |
| parent | Resolve merge conflict (diff) | |
Improve code consitency in Wikipedia Cog,Exceptions, and Error handler
Diffstat (limited to 'bot/exts/evergreen/wikipedia.py')
| -rw-r--r-- | bot/exts/evergreen/wikipedia.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/bot/exts/evergreen/wikipedia.py b/bot/exts/evergreen/wikipedia.py index 879146a6..63462433 100644 --- a/bot/exts/evergreen/wikipedia.py +++ b/bot/exts/evergreen/wikipedia.py @@ -47,9 +47,9 @@ class WikipediaSearch(commands.Cog): """Search wikipedia search string and return formatted first 10 pages found.""" params = WIKI_PARAMS | {"srlimit": 10, "srsearch": search} async with self.bot.http_session.get(url=SEARCH_API, params=params) as resp: - if resp.status != 200: + if (status := resp.status) != 200: log.info(f"Unexpected response `{resp.status}` while searching wikipedia for `{search}`") - raise ExternalAPIError("Wikipedia API") + raise ExternalAPIError("Wikipedia API", status) raw_data = await resp.json() number_of_results = raw_data["query"]["searchinfo"]["totalhits"] @@ -72,13 +72,10 @@ class WikipediaSearch(commands.Cog): return lines raw_data = await resp.json() - if raw_data.get("query", None) is None: - if raw_data.get("errors", None) is not None: - log.info("There was an error regarding the Wikipedia API query.") - else: - log.info("There was an issue when trying to communicate with the Wikipedia API, " - "please try again later.") - raise ExternalAPIError("Wikipedia API") + if not raw_data.get("query", None): + if error := raw_data.get("errors"): + log.error(f"There was an error while communicating with the Wikipedia API: {error}") + raise ExternalAPIError("Wikipedia API", status, error) number_of_results = raw_data["query"]["searchinfo"]["totalhits"] |