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

Handle 202 responses gracefully #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sondehub"
version = "0.3.2"
version = "0.3.3"
description = "SDK to access SondeHub open data, and helpers for uploading telemetry."
authors = ["Michaela <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion sondehub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import gzip


__version__ = "0.3.2"
__version__ = "0.3.3"

S3_BUCKET = "sondehub-history"

Expand Down
25 changes: 24 additions & 1 deletion sondehub/amateur.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,30 @@ def upload_telemetry(self, telem_list):
_upload_success = True
break

elif _req.status_code == 500:
elif _req.status_code == 202:
# 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']:
self.log_error("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: %s" % str(e))
self.log_debug("Content of 202 response: %s" % _req.text)

_upload_success = True
break

elif _req.status_code in [500,501,502,503,504]:
# Server Error, Retry.
self.log_debug(
"Error uploading to Sondehub Amateur. Status Code: %d %s."
Expand Down