Skip to content

Comments

try to recover from failure seen in production#107

Open
marcmengel wants to merge 1 commit intodevelopfrom
handle_JSONDecodeError
Open

try to recover from failure seen in production#107
marcmengel wants to merge 1 commit intodevelopfrom
handle_JSONDecodeError

Conversation

@marcmengel
Copy link
Contributor

Tired of seeing the stack traces for this in production...

Copy link
Collaborator

@goodenou goodenou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Marc. What do you think about expanding this a bit.

`try:
jobs_results.raise_for_status()
except requests.exceptions.HTTPError:
record_queue_log(
f"Ferry request HTTP {jobs_results.status_code}: {jobs_results.text}"
)
jobs_results.close()
return None

try:
jobs_dict = jobs_results.json()
except (requests.exceptions.JSONDecodeError, ValueError):
record_queue_log(
f"Ferry request returned non-JSON (HTTP {jobs_results.status_code}): {jobs_results.text}"
)
jobs_results.close()
return None
finally:
jobs_results.close()

if jobs_dict.get("errors") is not None:
record_queue_log(f"Ferry request yielded some errors: {jobs_dict.get('errors')}")

if not jobs_dict.get("data"):
record_queue_log("Ferry request yielded no results (valid JSON, empty data)")
return None`

The raise_for_status section catches upstream query errors, and we now log whether there was an error or just no data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants