Skip to content

Commit

Permalink
Fix ZeroDivisionError and others
Browse files Browse the repository at this point in the history
  • Loading branch information
joinemm committed Nov 30, 2023
1 parent 3f2e3e7 commit 8bd879c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cogs/lastfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,11 @@ def playcount_mapped(
output_start: int = 1,
output_end: int = 100,
):
# if everything has the same playcount, give max points
# or else we will run into ZeroDivisionError
if input_start == input_end:
return output_end

score = (x - input_start) / (input_end - input_start) * (
output_end - output_start
) + output_start
Expand Down
5 changes: 5 additions & 0 deletions modules/lastfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ async def api_request(self, method: str, params: dict) -> dict:
text = await response.text()
raise exceptions.LastFMError(error_code=response.status, message=text)

if content is None:
raise exceptions.LastFMError(
error_code=response.status, message="Unknown error"
)

error_code = content.get("error")
if error_code:
raise exceptions.LastFMError(
Expand Down

0 comments on commit 8bd879c

Please sign in to comment.