Skip to content

Commit

Permalink
Do not catch all http errors within the internal request function. (#25)
Browse files Browse the repository at this point in the history
To be able to catch and raise meaningful errors within the calling
context.
  • Loading branch information
csadorf authored Aug 17, 2022
1 parent bf60527 commit 194dc33
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions marketplace/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,10 @@ def userinfo(self):
userinfo.raise_for_status()
return userinfo.json()

def _request(self, op, path, **kwargs):
def _request(self, op, path, **kwargs) -> Response:
kwargs.setdefault("headers", {}).update(self.default_headers)
full_url = urljoin(self.marketplace_host_url, path)
response: Response = op(url=full_url, **kwargs)
if response.status_code >= 300:
message = (
f"Querying MarketPlace for {full_url} returned {response.status_code} "
f"because: {response.text}."
"Please check the host, client_id and token validity."
)
raise RuntimeError(message)
return response
return op(url=full_url, **kwargs)

def get(self, path: str, **kwargs):
return self._request(requests.get, path, **kwargs)
Expand Down

0 comments on commit 194dc33

Please sign in to comment.