Skip to content
Snippets Groups Projects
Commit 13efab7f authored by David Trattnig's avatar David Trattnig
Browse files

Less verbose logging when API fails. #33

parent b85aa202
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment