fix(bible): added error handling for if API.Bible is down
All checks were successful
Actions / Lint Code (Pylint) (push) Successful in 17s
Actions / Build Documentation (MkDocs) (push) Successful in 12s

This commit is contained in:
SeaswimmerTheFsh 2024-02-02 00:05:36 -05:00
parent 5d68f91169
commit 220e8da790
Signed by: cswimr
GPG key ID: B8953EC01E5C4063
2 changed files with 20 additions and 1 deletions

View file

@ -76,6 +76,8 @@ class Bible(commands.Cog):
raise bible.errors.BibleAccessError()
if response.status == 404:
raise bible.errors.NotFound()
if response.status == 503:
raise bible.errors.ServiceUnavailable()
return data["data"]
async def _get_books(self, bible_id: str) -> dict:
@ -94,6 +96,8 @@ class Bible(commands.Cog):
raise bible.errors.Unauthorized()
if response.status == 403:
raise bible.errors.BibleAccessError()
if response.status == 503:
raise bible.errors.ServiceUnavailable()
return data["data"]
async def _get_chapters(self, bible_id: str, book_id: str) -> dict:
@ -112,6 +116,8 @@ class Bible(commands.Cog):
raise bible.errors.Unauthorized()
if response.status == 403:
raise bible.errors.BibleAccessError()
if response.status == 503:
raise bible.errors.ServiceUnavailable()
return data["data"]
async def _get_verses(self, bible_id: str, book_id: str, chapter: int) -> dict:
@ -130,6 +136,8 @@ class Bible(commands.Cog):
raise bible.errors.Unauthorized()
if response.status == 403:
raise bible.errors.BibleAccessError()
if response.status == 503:
raise bible.errors.ServiceUnavailable()
return data["data"]
@commands.group(autohelp=True)
@ -166,6 +174,7 @@ class Bible(commands.Cog):
except (
bible.errors.BibleAccessError,
bible.errors.NotFound,
bible.errors.ServiceUnavailable,
bible.errors.Unauthorized,
) as e:
await ctx.send(e.message)
@ -205,6 +214,7 @@ class Bible(commands.Cog):
except (
bible.errors.BibleAccessError,
bible.errors.NotFound,
bible.errors.ServiceUnavailable,
bible.errors.Unauthorized,
) as e:
await ctx.send(e.message)