improved error handling in pulse to timestamp
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user