diff --git a/states/_modules/syncthing.py b/states/_modules/syncthing.py index d26cd93..748838a 100644 --- a/states/_modules/syncthing.py +++ b/states/_modules/syncthing.py @@ -35,9 +35,12 @@ def get_config(url="http://localhost:8384", verify=False, apikey=get_apikey()): req = Request(method="GET", url=fullurl) req.add_header("X-API-Key", apikey) - res = urlopen(req, context=get_context(verify)) + try: + res = urlopen(req, context=get_context(verify)) - ret = json.loads(res.read()) + ret = json.loads(res.read()) + except urllib.error.URLError: + return None if res.status == 200: return ret @@ -58,6 +61,8 @@ def set_config_options(url="http://localhost:8384", verify=False, apikey=get_api return False req.full_url = urljoin(url, err.headers['Location']) res = urlopen(req, context=get_context(verify)) + except urllib.error.URLError: + return None if res.status == 200: return True @@ -79,6 +84,8 @@ def set_config_gui(url="http://localhost:8384", verify=False, apikey=get_apikey( res = urlopen(req, context=get_context(verify)) except http.client.RemoteDisconnected as err: return True + except urllib.error.URLError: + return None if res.status == 200: return True @@ -99,6 +106,8 @@ def _set_config(url="http://localhost:8384", verify=False, apikey=get_apikey(), return None req.full_url = urljoin(url, err.headers['Location']) res = urlopen(req, context=get_context(verify)) + except urllib.error.URLError: + return None if res.status == 200: return True @@ -110,10 +119,13 @@ def insync(url="http://localhost:8384", verify=False, apikey=get_apikey()): req = Request(method="GET", url=fullurl) req.add_header("X-API-Key", apikey) - res = urlopen(req, context=get_context(verify)) - ret = json.loads(res.read()) - if res.status == 200: - return ret + try: + res = urlopen(req, context=get_context(verify)) + ret = json.loads(res.read()) + if res.status == 200: + return ret + except urllib.error.URLError: + return None return None @@ -123,8 +135,11 @@ def restart(url="http://localhost:8384", verify=False, apikey=get_apikey()): req = Request(method="POST", url=fullurl) req.add_header("X-API-Key", apikey) - res = urlopen(req, context=get_context(verify)) - if res.status == 200: - return {} + try: + res = urlopen(req, context=get_context(verify)) + if res.status == 200: + return {} + except urllib.error.URLError: + return None return None