Smargon": better handling of smargon connection exceptions
This commit is contained in:
@@ -5,6 +5,7 @@ import requests
|
||||
|
||||
from aare.common.beamline import MXBeamline
|
||||
from aare.common.coordinate import SmargonCoordinate, Coordinate, AerotechCoordinate
|
||||
from aare.common.exception_handler import SmargonCommunicationError
|
||||
|
||||
|
||||
class SmargonMode(Enum):
|
||||
@@ -35,21 +36,60 @@ class Smargon(object):
|
||||
raise Exception("unknown beamline")
|
||||
|
||||
def gonget(self, thing: str) -> dict:
|
||||
"""issue a GET for some API component on the smargopolo server"""
|
||||
"""issue a GET for some API component on the smargopolo server
|
||||
short hand for goniometer get"""
|
||||
cmd = f"{self.__base}/{thing}"
|
||||
r = requests.get(cmd)
|
||||
try:
|
||||
r = requests.get(cmd, timeout=2.0)
|
||||
except requests.exceptions.RequestException as e:
|
||||
raise SmargonCommunicationError(
|
||||
f"Smargon GET failed for '{thing}'",
|
||||
endpoint=thing,
|
||||
base_url=self.__base,
|
||||
operation="GET",
|
||||
) from e
|
||||
|
||||
if not r.ok:
|
||||
raise Exception(
|
||||
f"error getting {thing}; server returned {r.status_code} => {r.reason}"
|
||||
raise SmargonCommunicationError(
|
||||
f"Smargon GET returned HTTP {r.status_code} for '{thing}': {r.reason}",
|
||||
endpoint=thing,
|
||||
base_url=self.__base,
|
||||
operation="GET",
|
||||
status_code=r.status_code,
|
||||
)
|
||||
return r.json()
|
||||
|
||||
try:
|
||||
return r.json()
|
||||
except ValueError as e:
|
||||
raise SmargonCommunicationError(
|
||||
f"Smargon GET returned invalid JSON for '{thing}'",
|
||||
endpoint=thing,
|
||||
base_url=self.__base,
|
||||
operation="GET",
|
||||
status_code=r.status_code,
|
||||
) from e
|
||||
|
||||
def gonput(self, thing: str):
|
||||
"""issue a PUT command for some API component on the smargopolo server
|
||||
short hand for goniometer put"""
|
||||
cmd = f"{self.__base}/{thing}"
|
||||
r = requests.put(cmd)
|
||||
try:
|
||||
r = requests.put(cmd, timeout=2.0)
|
||||
except requests.exceptions.RequestException as e:
|
||||
raise SmargonCommunicationError(
|
||||
f"Smargon PUT failed for '{thing}'",
|
||||
endpoint=thing,
|
||||
base_url=self.__base,
|
||||
operation="PUT",
|
||||
) from e
|
||||
|
||||
if not r.ok:
|
||||
raise Exception(
|
||||
f"error putting {thing}; server returned {r.status_code} => {r.reason}"
|
||||
raise SmargonCommunicationError(
|
||||
f"Smargon PUT returned HTTP {r.status_code} for '{thing}': {r.reason}",
|
||||
endpoint=thing,
|
||||
base_url=self.__base,
|
||||
operation="PUT",
|
||||
status_code=r.status_code,
|
||||
)
|
||||
|
||||
def move_home(self, wait=False) -> None:
|
||||
|
||||
Reference in New Issue
Block a user