Skip to content

Commit

Permalink
Accommodate cloudflare errors (#823)
Browse files Browse the repository at this point in the history
* Add error check in emmet version

* Re-order error check

* Linting
  • Loading branch information
Jason Munro authored Jun 30, 2023
1 parent 8709dec commit bf5bfee
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions mp_api/client/mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ def __init__(
self.use_document_model = use_document_model
self.monty_decode = monty_decode

# Check if emmet version of server is compatible
emmet_version = version.parse(self.get_emmet_version())

try:
from mpcontribs.client import Client

Expand All @@ -222,9 +225,6 @@ def __init__(
self.contribs = None
warnings.warn(f"Problem loading MPContribs client: {error}")

# Check if emmet version of server os compatible
emmet_version = version.parse(self.get_emmet_version())

if version.parse(emmet_version.base_version) < version.parse(
_MAPI_SETTINGS.MIN_EMMET_VERSION
):
Expand Down Expand Up @@ -381,7 +381,14 @@ def get_emmet_version(self):
Returns: version as a string
"""
return get(url=self.endpoint + "heartbeat").json()["version"]

response = get(url=self.endpoint + "heartbeat").json()

error = response.get("error", None)
if error:
raise MPRestError(error)

return response["version"]

def get_material_id_from_task_id(self, task_id: str) -> Union[str, None]:
"""Returns the current material_id from a given task_id. The
Expand Down

0 comments on commit bf5bfee

Please sign in to comment.