raise exceptions

This commit is contained in:
Administrator 2023-10-10 00:01:33 +03:00
parent 4cb525ac11
commit 9899812fe7

View File

@ -19,17 +19,17 @@ class YandexAuthView(BaseView):
'code': code 'code': code
}) })
if response.status_code != 200: if response.status_code != 200:
self.logger.warning("Cant access, json: %s", response.json()) raise Exception("Cant access, json: " + str(response.json()))
return '/welcome' return '/welcome'
access_token = response.json().get('access_token') access_token = response.json().get('access_token')
if access_token is None: if access_token is None:
self.logger.warning('no access token') raise Exception('no access token')
return '/welcome' return '/welcome'
info_response = get('https://login.yandex.ru/info', headers={ info_response = get('https://login.yandex.ru/info', headers={
'Authorization': f'OAuth {access_token}' 'Authorization': f'OAuth {access_token}'
}) })
if info_response.status_code != 200: if info_response.status_code != 200:
self.logger.warning("Cant access, json: %s", response.json()) raise Exception("Cant access, json: " + str(response.json()))
return '/welcome' return '/welcome'
data = info_response.json() data = info_response.json()
yandex_id = data['id'] yandex_id = data['id']