forked from blizzthewolf/SeaCogs
fix(bible): added error handling for if API.Bible is down
This commit is contained in:
parent
5d68f91169
commit
220e8da790
2 changed files with 20 additions and 1 deletions
|
@ -76,6 +76,8 @@ class Bible(commands.Cog):
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError()
|
||||||
if response.status == 404:
|
if response.status == 404:
|
||||||
raise bible.errors.NotFound()
|
raise bible.errors.NotFound()
|
||||||
|
if response.status == 503:
|
||||||
|
raise bible.errors.ServiceUnavailable()
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
async def _get_books(self, bible_id: str) -> dict:
|
async def _get_books(self, bible_id: str) -> dict:
|
||||||
|
@ -94,6 +96,8 @@ class Bible(commands.Cog):
|
||||||
raise bible.errors.Unauthorized()
|
raise bible.errors.Unauthorized()
|
||||||
if response.status == 403:
|
if response.status == 403:
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError()
|
||||||
|
if response.status == 503:
|
||||||
|
raise bible.errors.ServiceUnavailable()
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
async def _get_chapters(self, bible_id: str, book_id: str) -> dict:
|
async def _get_chapters(self, bible_id: str, book_id: str) -> dict:
|
||||||
|
@ -112,6 +116,8 @@ class Bible(commands.Cog):
|
||||||
raise bible.errors.Unauthorized()
|
raise bible.errors.Unauthorized()
|
||||||
if response.status == 403:
|
if response.status == 403:
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError()
|
||||||
|
if response.status == 503:
|
||||||
|
raise bible.errors.ServiceUnavailable()
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
async def _get_verses(self, bible_id: str, book_id: str, chapter: int) -> dict:
|
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()
|
raise bible.errors.Unauthorized()
|
||||||
if response.status == 403:
|
if response.status == 403:
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError()
|
||||||
|
if response.status == 503:
|
||||||
|
raise bible.errors.ServiceUnavailable()
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
@commands.group(autohelp=True)
|
@commands.group(autohelp=True)
|
||||||
|
@ -166,6 +174,7 @@ class Bible(commands.Cog):
|
||||||
except (
|
except (
|
||||||
bible.errors.BibleAccessError,
|
bible.errors.BibleAccessError,
|
||||||
bible.errors.NotFound,
|
bible.errors.NotFound,
|
||||||
|
bible.errors.ServiceUnavailable,
|
||||||
bible.errors.Unauthorized,
|
bible.errors.Unauthorized,
|
||||||
) as e:
|
) as e:
|
||||||
await ctx.send(e.message)
|
await ctx.send(e.message)
|
||||||
|
@ -205,6 +214,7 @@ class Bible(commands.Cog):
|
||||||
except (
|
except (
|
||||||
bible.errors.BibleAccessError,
|
bible.errors.BibleAccessError,
|
||||||
bible.errors.NotFound,
|
bible.errors.NotFound,
|
||||||
|
bible.errors.ServiceUnavailable,
|
||||||
bible.errors.Unauthorized,
|
bible.errors.Unauthorized,
|
||||||
) as e:
|
) as e:
|
||||||
await ctx.send(e.message)
|
await ctx.send(e.message)
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Unauthorized(Exception):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str = error(
|
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](<https://seacogs.coastalcommits.com/bible/#setup>)."
|
"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](<https://seacogs.coastalcommits.com/bible/#setup>)."
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
|
@ -30,3 +30,12 @@ class NotFound(Exception):
|
||||||
):
|
):
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
self.message = 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
|
||||||
|
|
Loading…
Reference in a new issue