Skip to content

Commit

Permalink
Capture the API error data response, if present in the response.
Browse files Browse the repository at this point in the history
The MGX API returns a json with the error message, which is useful
for debugging.
  • Loading branch information
mberacochea committed Feb 16, 2024
1 parent 4b145c0 commit 6235f03
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion emgapi/metagenomics_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ def add_analysis(self, mgya: str, sequence_accession: str):
try:
response = self.post_request(endpoint="datasets", data=data)
except HTTPError as http_error:
logging.exception(f"POST request failed. HTTP Error: {http_error}")
try:
response_json = http_error.response.json()
logging.error(f"API response content: {response_json}")
except:
pass
raise http_error
return response

Expand Down Expand Up @@ -145,6 +149,11 @@ def check_analysis(self, mgya: str, sequence_accession: str, metadata=None):
response = self.get_request(endpoint=endpoint, params=params)
except HTTPError as http_error:
logging.error(f"Get API request failed. HTTP Error: {http_error}")
try:
response_json = http_error.response.json()
logging.error(f"API response content: {response_json}")
except:
pass
return analysis_registry_id, metadata_match

data = response.json()
Expand Down

0 comments on commit 6235f03

Please sign in to comment.