flair-systems / flair-api-client-py

Python Client for Flair API
Apache License 2.0
15 stars 5 forks source link

Raise ApiError Exception if unauthorized credentials used & use requests Session() object #5

Open RobertD502 opened 2 years ago

RobertD502 commented 2 years ago

As it stands, using unauthorized credentials results in a TypeError exception being raised in the token_header function:

  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flair_api/client.py", line 223, in get
    headers=dict(self.token_header(), **DEFAULT_CLIENT_HEADERS)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flair_api/client.py", line 205, in token_header
    headers = {'Authorization': 'Bearer ' + self.token}
TypeError: can only concatenate str (not "NoneType") to str

The proposed change would instead raise a proper exception within the oauth_token function with the following output:

flair_api.client.ApiError: ApiError<HTTP Response: 401>