hydroshare / hs_restclient

Python client for the https://www.hydroshare.org REST API
BSD 3-Clause "New" or "Revised" License
6 stars 8 forks source link

Fix usage of HydroShareHTTPException #120

Closed kylecombes closed 4 years ago

kylecombes commented 4 years ago

It looks like generators.py was not updated to use the latest signature for HydroShareHTTPException:


class HydroShareHTTPException(HydroShareException):
    """ Exception used to communicate HTTP errors from HydroShare server

        Arguments in tuple passed to constructor must be: (url, status_code, params).
        url and status_code are of type string, while the optional params argument
        should be a dict.
    """
    def __init__(self, response):
        super(HydroShareHTTPException, self).__init__(response)
        self.url = response.request.url
        self.method = response.request.method
        self.status_code = response.status_code
        self.status_msg = response.text if response.text else "No status message"

Passing a tuple (as is currently done) results in the following error:

File "/home/kyle/anaconda3/envs/scope/lib/python3.8/site-packages/hs_restclient/generators.py", line 12, in resultsListGenerator
        raise HydroShareHTTPException((url, 'GET', r.status_code, params))
      File "/home/kyle/anaconda3/envs/scope/lib/python3.8/site-packages/hs_restclient/exceptions.py", line 61, in __init__
        self.url = response.request.url
    AttributeError: 'tuple' object has no attribute 'request'
kylecombes commented 4 years ago

Also, I'd imagine this is a known fact, but HydroShare internal server errors result in a whole HTML page being sent back in the body of the API response.