Beispiel #1
0
 async def request_token(self, client_secret: str, code: str) -> CredentialsFlowResponse:
     """Request and return token, raise VKAuthError otherwise"""
     http = AiohttpClient()
     response = await http.request_json("get", self.token_request_link)
     await http.close()
     try:
         return CredentialsFlowResponse(**response)
     except ValidationError:
         error = RequestTokenError(**response)
         raise VKAPIError(error_description=str(error))
Beispiel #2
0
    async def validate(
        self,
        method: str,
        data: dict,
        response: typing.Any,
        ctx_api: typing.Union["ABCAPI", "API"],
    ) -> typing.Union[typing.Any, typing.NoReturn]:
        if "error" not in response:
            return response

        code, msg = response["error"].get("error_code"), response["error"].get("error_msg")

        if ctx_api.ignore_errors:
            return None

        raise VKAPIError(code, msg, response)
Beispiel #3
0
from vkbottle.exception_factory import VKAPIError

try:
    raise VKAPIError(2, "Some exception occurred")
except VKAPIError(3) as e:
    print("Oh, third exception.")
except VKAPIError(2) as e:
    print("Oh, second exception.")
except VKAPIError():
    print("Unknown vk error")