Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.7.5-beta7 - Better handling of error responses from Sondehub #911

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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