Skip to content

Commit

Permalink
feat: Add meaningful error when trying to request gacha with expired …
Browse files Browse the repository at this point in the history
…params
  • Loading branch information
jokelbaf committed Nov 17, 2024
1 parent b2ad159 commit 3153c37
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kuro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
from .errors import *
from .types import *

__version__ = "0.4.0"
__version__ = "0.4.1"
4 changes: 3 additions & 1 deletion kuro/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class KuroError(Exception):

def __init__(self, response: typing.Mapping[str, typing.Any]) -> None:
self.response = response
self.api_msg = response.get("msg", "")
self.api_msg = response.get("msg", response.get("message", ""))

self.retcode = self.retcode or RETCODES[self.api_msg]
self.msg = self.msg or ERROR_TRANSLATIONS[self.retcode]
Expand All @@ -44,13 +44,15 @@ def __repr__(self) -> str:
RETCODES: typing.Mapping[str, int] = {
"": 0, # Unknown error
"系统异常": 1, # System error
"请求游戏获取日志异常!": 2, # Gacha history params expired
}
"""Kuro.py's custom error codes matched with API error messages."""


ERROR_TRANSLATIONS: typing.Mapping[int, str] = {
0: "Unknown error occurred when requesting the API",
1: "System error",
2: "Gacha history params expired",
}
"""English error messages translated from Kuro.py's custom error codes."""

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test = ["pytest", "python-dotenv", "pytest-asyncio"]

[tool.poetry]
name = "kuro.py"
version = "0.4.0"
version = "0.4.1"
description = "Async API wrapper for KuroBBS written in Python."
authors = [
"JokelBaf <[email protected]>",
Expand Down

0 comments on commit 3153c37

Please sign in to comment.