Skip to content

Commit

Permalink
Merge pull request #911 from darksidelemm/testing
Browse files Browse the repository at this point in the history
v1.7.5-beta7 - Better handling of error responses from Sondehub
  • Loading branch information
darksidelemm authored Sep 21, 2024
2 parents a78d3b1 + c6ec22a commit 84d3359
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion auto_rx/autorx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# MINOR - New sonde type support, other fairly big changes that may result in telemetry or config file incompatability issus.
# PATCH - Small changes, or minor feature additions.

__version__ = "1.7.5-beta6"
__version__ = "1.7.5-beta7"

# Global Variables

Expand Down
32 changes: 28 additions & 4 deletions auto_rx/autorx/sondehub.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,28 @@ def upload_telemetry(self, telem_list):
continue

elif (_req.status_code == 201) or (_req.status_code == 202):
self.log_debug(
"Sondehub reported issue when adding packets to DB. Status Code: %d %s."
% (_req.status_code, _req.text)
)
# A 202 return code means there was some kind of data issue.
# We expect a response of the form {"message": "error message", "errors":[], "warnings":[]}
try:
_resp_json = _req.json()

for _error in _resp_json['errors']:
if 'z-check' not in _error["error_message"]:
self.log_error("Payload data error: " + _error["error_message"])
else:
self.log_debug("Payload data error: " + _error["error_message"])
if 'payload' in _error:
self.log_debug("Payload data associated with error: " + str(_error['payload']))

for _warning in _resp_json['warnings']:
self.log_warning("Payload data warning: " + _warning["warning_message"])
if 'payload' in _warning:
self.log_debug("Payload data associated with warning: " + str(_warning['payload']))

except Exception as e:
self.log_error("Error when parsing 202 response as JSON: %s" % str(e))
self.log_debug("Content of 202 response: %s" % _req.text)

_upload_success = True
break

Expand Down Expand Up @@ -576,6 +594,12 @@ def log_error(self, line):
"""
logging.error("Sondehub Uploader - %s" % line)

def log_warning(self, line):
""" Helper function to log an error message with a descriptive heading.
Args:
line (str): Message to be logged.
"""
logging.warning("Sondehub Uploader - %s" % line)

if __name__ == "__main__":
# Test Script
Expand Down

0 comments on commit 84d3359

Please sign in to comment.