diff --git a/src/plugins/monitor.py b/src/plugins/monitor.py index 87ecdcf2820e376bec6485c19f31df11ea162ec1..d6227ea4139b4175bff95065b57b90c3205bb09e 100644 --- a/src/plugins/monitor.py +++ b/src/plugins/monitor.py @@ -197,16 +197,28 @@ class AuraMonitor: body["is_healthy"] = is_healthy body["details"] = json.dumps(data, default=str) json_data = json.dumps(body, default=str) - url = self.config.get("api_engine_store_health") url = url.replace("${ENGINE_NUMBER}", str(self.config.get("api_engine_number"))) headers = {'content-type': 'application/json'} - r = requests.post(url, data=json_data, headers=headers) + response = requests.Response() + response.status_code = 404 - if r.status_code == 204: - self.logger.info("Successfully posted healthy=%s state to Engine API!" % is_healthy) - else: - self.logger.error("HTTP %s | Error while pushing health state to Engine API: %s" % (r.status_code, str(r.json()))) + try: + response = requests.post(url, data=json_data, headers=headers) + if response.status_code == 204: + self.logger.info("Successfully posted healthy=%s state to Engine API!" % is_healthy) + else: + msg = SU.red(f"HTTP {response.status_code} | Error while pushing health state to Engine API: {response.json()}") + self.logger.error(msg) + except requests.exceptions.ConnectionError: + self.logger.error(SU.red(f"Bad Request when posting health-status to {url}")) + return response + except requests.exceptions.Timeout: + self.logger.error(SU.red(f"Timeout when posting health-status to {url}")) + return response + except: + self.logger.error(SU.red(f"Unknown Exception when posting health-status to {url}")) + return response def update_status(self): diff --git a/src/plugins/trackservice.py b/src/plugins/trackservice.py index df8140e2eca97721508bacd5c7f9292837fc134b..ca2ac32b335e22ed4c89e7dd47309d8bf1f12000 100644 --- a/src/plugins/trackservice.py +++ b/src/plugins/trackservice.py @@ -162,16 +162,30 @@ class TrackServiceHandler(): Posts the given `PlaylistEntry` to the Engine API Playlog. """ data = SU.clean_dictionary(data) - self.logger.info("Posting playlog to Engine API...") url = self.config.get("api_engine_store_playlog") headers = {'content-type': 'application/json'} body = json.dumps(data, indent=4, sort_keys=True, default=str) self.logger.debug("Playlog Data: " + body) - response = requests.post(url, data=body, headers=headers) - if response.status_code != 204 or response.status_code != 204: - msg = f"Error while posting playlog to Engine API: {response.reason} (Error {response.status_code})\n" - self.logger.info(SU.red(msg) + response.content.decode("utf-8")) + response = requests.Response() + response.status_code = 404 + + try: + response = requests.post(url, data=body, headers=headers) + if response.status_code != 204: + msg = f"Error while posting playlog to Engine API: {response.reason} (Error {response.status_code})\n" + self.logger.info(SU.red(msg) + response.content.decode("utf-8")) + except requests.exceptions.ConnectionError: + self.logger.error(SU.red(f"Bad Request when posting playlog to {url}")) + return response + except requests.exceptions.Timeout: + self.logger.error(SU.red(f"Timeout when posting playlog to {url}")) + return response + except: + self.logger.error(SU.red(f"Unknown Exception when posting playlog to {url}")) + return response + + def store_clock_info(self, data): @@ -218,10 +232,23 @@ class TrackServiceHandler(): headers = {'content-type': 'application/json'} body = json.dumps(data, indent=4, sort_keys=True, default=str) self.logger.debug("Clock Data: " + body) - response = requests.put(url, data=body, headers=headers) - if response.status_code != 204 or response.status_code != 204: - msg = f"Error while posting clock-info to Engine API: {response.reason} (Error {response.status_code})\n" - self.logger.info(SU.red(msg) + response.content.decode("utf-8")) + response = requests.Response() + response.status_code = 404 + + try: + response = requests.put(url, data=body, headers=headers) + if response.status_code != 204: + msg = f"Error while posting clock-info to Engine API: {response.reason} (Error {response.status_code})\n" + self.logger.info(SU.red(msg) + response.content.decode("utf-8")) + except requests.exceptions.ConnectionError: + self.logger.error(SU.red(f"Bad Request when posting clock-info to {url}")) + return response + except requests.exceptions.Timeout: + self.logger.error(SU.red(f"Timeout when posting clock-info to {url}")) + return response + except: + self.logger.error(SU.red(f"Unknown Exception when posting clock-info to {url}")) + return response