mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2026-02-04 10:14:15 +02:00
Raise instances of exceptions for consistency
This commit is contained in:
@@ -81,12 +81,12 @@ class DiscordOAuth2HttpClient(abc.ABC):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def save_authorization_token(token: dict):
|
def save_authorization_token(token: dict):
|
||||||
raise NotImplementedError
|
raise NotImplementedError()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_authorization_token() -> dict:
|
def get_authorization_token() -> dict:
|
||||||
raise NotImplementedError
|
raise NotImplementedError()
|
||||||
|
|
||||||
def _fetch_token(self, state):
|
def _fetch_token(self, state):
|
||||||
discord = self._make_session(state=state)
|
discord = self._make_session(state=state)
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ class User(DiscordModelsBase):
|
|||||||
try:
|
try:
|
||||||
data = {"access_token": current_app.discord.get_authorization_token()["access_token"]}
|
data = {"access_token": current_app.discord.get_authorization_token()["access_token"]}
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise exceptions.Unauthorized
|
raise exceptions.Unauthorized()
|
||||||
return self._bot_request(f"/guilds/{guild_id}/members/{self.id}", method="PUT", json=data) or dict()
|
return self._bot_request(f"/guilds/{guild_id}/members/{self.id}", method="PUT", json=data) or dict()
|
||||||
|
|
||||||
def fetch_guilds(self) -> list:
|
def fetch_guilds(self) -> list:
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class JSONBool(object):
|
|||||||
return cls(True)
|
return cls(True)
|
||||||
if value.lower() == "false":
|
if value.lower() == "false":
|
||||||
return cls(False)
|
return cls(False)
|
||||||
raise ValueError
|
raise ValueError()
|
||||||
|
|
||||||
|
|
||||||
def json_bool(value):
|
def json_bool(value):
|
||||||
@@ -45,7 +45,7 @@ def requires_authorization(view):
|
|||||||
@functools.wraps(view)
|
@functools.wraps(view)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
if not current_app.discord.authorized:
|
if not current_app.discord.authorized:
|
||||||
raise exceptions.Unauthorized
|
raise exceptions.Unauthorized()
|
||||||
return view(*args, **kwargs)
|
return view(*args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|||||||
Reference in New Issue
Block a user