Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during error handling when token can not be retrieved #1

Open
totycro opened this issue Jul 6, 2020 · 0 comments
Open

Error during error handling when token can not be retrieved #1

totycro opened this issue Jul 6, 2020 · 0 comments

Comments

@totycro
Copy link

totycro commented Jul 6, 2020

Hi,

I just accidentally used the library without the necessary environment variables and got an error during error handling here:
https://github.com/dcs4cop/xcube-gen/blob/master/xcube_gen/jobapi.py#L71

Maybe this raise str(e) could be changed to a raise Exception(e) or just a raise, or not have a try-except in the first place.

from xcube_gen.jobapi import JobApi
api = JobApi()
api.whoami
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
/opt/conda/envs/eurodatacube-0.18.5/lib/python3.8/site-packages/xcube_gen/jobapi.py in _get_token_for_client(self)
     67 
---> 68             token.raise_for_status()
     69             return token.json()

/opt/conda/envs/eurodatacube-0.18.5/lib/python3.8/site-packages/requests/models.py in raise_for_status(self)
    940         if http_error_msg:
--> 941             raise HTTPError(http_error_msg, response=self)
    942 

HTTPError: 401 Client Error: Unauthorized for url: https://edc.eu.auth0.com/oauth/token

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-3-8b27a29fec2f> in <module>
      1 from xcube_gen.jobapi import JobApi
----> 2 api = JobApi()
      3 api.whoami

/opt/conda/envs/eurodatacube-0.18.5/lib/python3.8/site-packages/xcube_gen/jobapi.py in __init__(self, user_name)
     41         self._auth_client_secret = os.getenv("XCUBE_GEN_AUTH_CLIENT_SECRET")
     42 
---> 43         self._token = self._get_token_for_client()
     44         # self._user_name = self._get_user_info_from_auth0(self._token['access_token'])
     45         if self._token:

/opt/conda/envs/eurodatacube-0.18.5/lib/python3.8/site-packages/xcube_gen/jobapi.py in _get_token_for_client(self)
     69             return token.json()
     70         except BaseException as e:
---> 71             raise str(e)
     72 
     73     def _get_user_info_from_auth0(self, token: str):

TypeError: exceptions must derive from BaseException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant