diff --git a/copy-iris-items.pyw b/copy-iris-items.pyw index b82f09c..aacb975 100644 --- a/copy-iris-items.pyw +++ b/copy-iris-items.pyw @@ -89,9 +89,13 @@ def get_modified_items(config, itemtype): url = f"{scheme}://{svr.host}:{svr.port}/api/atelier/v1/{svr.namespace}/modified/{itemtype}?generated=0" rq = urq.Request(url, data=b'[]', headers={'Content-Type': 'application/json'}, method='POST') - # Get and convert to JSON - with urq.urlopen(rq) as rsp: - data = json.load(rsp) + try: + # Get and convert to JSON + with urq.urlopen(rq) as rsp: + data = json.load(rsp) + except urq.URLError: + logging.error(f"Accessing {url}:") + raise return data @@ -107,8 +111,12 @@ def get_items_for_type(config, itemtype): url = f"{scheme}://{svr.host}:{svr.port}/api/atelier/v1/{svr.namespace}/docnames/{itemtype}" # Get and convert to JSON - with urq.urlopen(url) as rsp: - data = json.load(rsp) + try: + with urq.urlopen(url) as rsp: + data = json.load(rsp) + except urq.URLError: + logging.error(f"Accessing {url}:") + raise return data @@ -200,9 +208,12 @@ def retrieve_item(config, item): scheme = 'https' if svr.https else 'http' url = f"{scheme}://{svr.host}:{svr.port}/api/atelier/v1/{svr.namespace}/doc/{name}" - rsp = urq.urlopen(url) - with rsp: - data = json.load(rsp) + try: + with urq.urlopen(url) as rsp: + data = json.load(rsp) + except urq.URLError: + logging.error(f"Accessing {url}:") + raise # Contents may be returned line-by-line content = data['result']['content'] diff --git a/data_handler.py b/data_handler.py index 0e4700f..b590efd 100644 --- a/data_handler.py +++ b/data_handler.py @@ -33,8 +33,13 @@ def get_export(svr, name:str): query = f"SELECT Tmp_CII.GetExport('{name}') AS result" data = json.dumps({ "query": query }).encode() rq = urq.Request(url, data=data, headers={'Content-Type': 'application/json'}, method='POST') - with urq.urlopen(rq) as rsp: - data = json.load(rsp) + + try: + with urq.urlopen(rq) as rsp: + data = json.load(rsp) + except urq.URLError: + logging.error(f"Accessing [POST] {url}:") + raise # Check for errors errors = data['status']['errors'] @@ -67,8 +72,12 @@ def list_lookup_tables(svr, specs:list): # Run query rq = urq.Request(url, data=data, headers={'Content-Type': 'application/json'}, method='POST') - with urq.urlopen(rq) as rsp: - data = json.load(rsp) + try: + with urq.urlopen(rq) as rsp: + data = json.load(rsp) + except urq.URLError: + logging.error(f"Accessing [POST] {url}:") + raise # Check for errors errors = data['status']['errors'] @@ -91,8 +100,13 @@ def init(svr): query = "SELECT 1 FROM %Dictionary.ClassDefinition WHERE ID = 'Tmp.CII.Procs'" data = json.dumps({ "query": query }).encode() rq = urq.Request(url, data=data, headers={'Content-Type': 'application/json'}, method='POST') - with urq.urlopen(rq) as rsp: - data = json.load(rsp) + + try: + with urq.urlopen(rq) as rsp: + data = json.load(rsp) + except urq.URLError: + logging.error(f"Accessing [POST] {url}:") + raise # If the class still exists, we're done if data['result']['content']: @@ -101,8 +115,13 @@ def init(svr): # Get the SQL to create the stored procedure data = json.dumps({ "query": CREATE_EXPORT_PROC }).encode() rq = urq.Request(url, data=data, headers={'Content-Type': 'application/json'}, method='POST') - with urq.urlopen(rq) as rsp: - data = json.load(rsp) + + try: + with urq.urlopen(rq) as rsp: + data = json.load(rsp) + except urq.URLError: + logging.error(f"Accessing [POST] {url}:") + raise errors = data['status']['errors'] if errors: @@ -126,8 +145,13 @@ def cleanup(svr:dict): query = "DROP PROCEDURE Tmp_CII.GetExport" data = json.dumps({ "query": query }).encode() rq = urq.Request(url, data=data, headers={'Content-Type': 'application/json'}, method='POST') - with urq.urlopen(rq) as rsp: - data = json.load(rsp) + + try: + with urq.urlopen(rq) as rsp: + data = json.load(rsp) + except urq.URLError: + logging.error(f"Accessing [POST] {url}:") + raise # If that returned errors, don't raise but do add a warning to the log errors = data['status']['errors']