Skip to content

Commit

Permalink
Improve exception and allow get to hvae parameters (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanfranklin authored Nov 22, 2023
1 parent ef0478f commit dc786e9
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions geoapi/utils/agave.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,19 @@


class AgaveListingError(Exception):
'''' Unable to list directory from agave
''' Exception raised when unable to list directory from Agave.
Attributes:
response -- response object that caused the error
message -- explanation of the error
'''
pass

def __init__(self, response, message):
self.response = response
self.message = message
super().__init__(self.message)

def __str__(self):
return f"{self.message} | Response: {self.response}"


class AgaveFileGetError(Exception):
Expand Down Expand Up @@ -97,8 +107,8 @@ def __init__(self, jwt=None, token=None, tenant=None):
self.base_url = get_api_server(tenant) if tenant else self.BASE_URL
self.client = client

def get(self, url):
return self.client.get(self.base_url + url)
def get(self, url, params=None):
return self.client.get(self.base_url + url, params=params)

def systemsList(self):
resp = self.get(quote('/systems/'))
Expand All @@ -121,8 +131,9 @@ def listing(self, systemId: str, path: str) -> List[AgaveFileListing]:
url = quote('/files/listings/system/{}/{}?limit=10000'.format(systemId, path))
resp = self.get(url)
if resp.status_code != 200:
raise AgaveListingError(f"Unable to perform files listing of {systemId}/{path}. "
f"Status code: {resp.status_code}")
e = AgaveListingError(message=f"Unable to perform files listing of {systemId}/{path}. Status code: {resp.status_code}",
response=resp)
raise e
listing = resp.json()
out = [AgaveFileListing(d) for d in listing["result"]]
return out
Expand Down

0 comments on commit dc786e9

Please sign in to comment.