Skip to content

Commit

Permalink
🐛 fix exception param
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Oct 15, 2023
1 parent 01b8fd7 commit d188138
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions nonebot/adapters/satori/exception.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from typing import Optional

from nonebot.drivers import Response
Expand All @@ -16,27 +15,17 @@ def __init__(self):
class ActionFailed(BaseActionFailed, SatoriAdapterException):
def __init__(self, response: Response):
self.status_code: int = response.status_code
self.code: Optional[int] = None
self.message: Optional[str] = None
self.data: Optional[dict] = None
if response.content:
body = json.loads(response.content)
self._prepare_body(body)
self.headers = response.headers
self.content = response.content

def __repr__(self) -> str:
return (
f"<ActionFailed: {self.status_code}, code={self.code}, "
f"message={self.message}, data={self.data}>"
f"<{self.__class__.__name__}: {self.status_code}, headers={self.headers}, content={self.content}>"
)

def __str__(self):
return self.__repr__()

def _prepare_body(self, body: dict):
self.code = body.get("code")
self.message = body.get("message")
self.data = body.get("data")


class BadRequestException(ActionFailed):
pass
Expand Down

0 comments on commit d188138

Please sign in to comment.