Skip to content

Commit

Permalink
Change authentication function to give server response
Browse files Browse the repository at this point in the history
  • Loading branch information
rushabhvaria committed Mar 31, 2023
1 parent fc36098 commit 8591b7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions pinterest/utils/refresh_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ def get_new_access_token(
body=data,
timeout=5
)
if not response.status == 200:
raise SdkException(reason="Authentication error. \
Kindly check if the following variables are correct: [PINTEREST_ACCESS_TOKEN] or \
[PINTEREST_APP_ID, PINTEREST_APP_SECRET, PINTEREST_REFRESH_ACCESS_TOKEN]")
if response.status == 401:
raise SdkException(
status=response.status,
reason=response.reason,
body="Authentication error. " +
"Kindly check if the following variables are correct: [PINTEREST_ACCESS_TOKEN] or " +
"[PINTEREST_APP_ID, PINTEREST_APP_SECRET, PINTEREST_REFRESH_ACCESS_TOKEN]. " +
f"Response from server: {response.body}"
)
elif response.status != 200:
raise SdkException(http_resp=response)

data = json.loads(response.data)

Expand Down
4 changes: 2 additions & 2 deletions pinterest/utils/sdk_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class SdkException(Exception):
"""Raises an exception for Model's Errors"""
def __init__(self, status=None, reason=None, http_resp=None):
def __init__(self, status=None, reason=None, http_resp=None, body=None):
if http_resp:
self.status = http_resp.status
self.reason = http_resp.reason
Expand All @@ -13,7 +13,7 @@ def __init__(self, status=None, reason=None, http_resp=None):
else:
self.status = status
self.reason = reason
self.body = None
self.body = body
self.headers = None

def __str__(self):
Expand Down

0 comments on commit 8591b7b

Please sign in to comment.