diff --git a/bible/bible.py b/bible/bible.py index 064c736..518d9b5 100644 --- a/bible/bible.py +++ b/bible/bible.py @@ -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) diff --git a/bible/errors.py b/bible/errors.py index a5a6a2e..c4c0592 100644 --- a/bible/errors.py +++ b/bible/errors.py @@ -16,7 +16,7 @@ class Unauthorized(Exception): def __init__( self, message: str = error( - "The API key for API.bible is missing or invalid. Please report this to the bot owner.\nIf you are the bot owner, please check the documentation [here]()." + "The API key for API.Bible is missing or invalid. Please report this to the bot owner.\nIf you are the bot owner, please check the documentation [here]()." ), ): super().__init__(message) @@ -30,3 +30,12 @@ class NotFound(Exception): ): super().__init__(message) self.message = message + + +class ServiceUnavailable(Exception): + def __init__( + self, + message: str = error("The API.Bible service is currently unavailable."), + ): + super().__init__(message) + self.message = message