Skip to content

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

Open
@totycro

Description

@totycro

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions