diff --git a/src/cristallina/utils.py b/src/cristallina/utils.py index cffc0c9..16232d1 100644 --- a/src/cristallina/utils.py +++ b/src/cristallina/utils.py @@ -7,6 +7,7 @@ from collections import defaultdict import requests import datetime +from json import JSONDecodeError import logging @@ -675,9 +676,10 @@ def pulseid_to_timestamp(pulse_id): r = requests.get(f"https://data-api.psi.ch/api/4/map/pulse/sf-databuffer/{pulse_id}") try: ns_timestamp = r.json() - except JSONDecodeError as e: - raise ValueError(f"Cannot convert pulse id {pulse_id} to timestamp.") + timestamp = datetime.datetime.fromtimestamp(ns_timestamp/1E9) + except (JSONDecodeError, TypeError) as e: + raise ValueError(f"Cannot convert pulse id {pulse_id} to timestamp. Cause: {e}") - return datetime.datetime.fromtimestamp(ns_timestamp/1E9) + return timestamp