Skip to content

Commit

Permalink
handle empty responses w/ errors
Browse files Browse the repository at this point in the history
  • Loading branch information
edsu committed Apr 28, 2022
1 parent c6fb387 commit 767517e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions twarc/expansions.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ def ensure_flattened(data):
log.warning(f"Unable to expand dictionary without includes: {data}")
return flatten(data)

# If it's just an object with errors return an empty list
elif (
isinstance(data, dict)
and "data" not in data
and "includes" not in data
and "errors" in data
):
return []

# If it's a single response and both "includes" and "data" are missing, it is already flattened
elif isinstance(data, dict) and "data" not in data and "includes" not in data:
return [data]
Expand Down

0 comments on commit 767517e

Please sign in to comment.