Skip to content

LG-4917: Surface X-Request-ID header in SDK errors #48

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 20 additions & 3 deletions lightspark/requests/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,35 @@ def execute_graphql(
result = r.json()
if "errors" in result:
errors = result["errors"]
request_id = r.headers.get(
"X-Request-ID", "Unknown"
) # Get X-Request-ID from headers
logger.error(
"GraphQL error occurred. Request ID: %s, Errors: %s",
request_id,
errors,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not totally sure whether this will serialize properly like this since it's an array. Might want to try in a test script.

Copy link
Author

Choose a reason for hiding this comment

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

got it. will test it out.

)
raise LightsparkException(
"GRAPHQL_ERROR", f"A GraphQL error occurred: {errors}"
"GRAPHQL_ERROR",
f"A GraphQL error occurred: {errors}. Request ID: {request_id}",
) # TODO better error handling
return result["data"]
except requests.HTTPError as e:
request_id = r.headers.get(
"X-Request-ID", "Unknown"
) # Get X-Request-ID from headers
logger.error("HTTP request error. Status code: %d", r.status_code)
raise LightsparkException("HTTP_ERROR", str(e)) from e
raise LightsparkException(
"HTTP_ERROR", f"{str(e)}. Request ID: {request_id}"
) from e
except Exception as e:
logger.exception(e)

try:
logger.error(r.text)
request_id = r.headers.get(
"X-Request-ID", "Unknown"
) # Extract X-Request-ID
logger.error("Request ID: %s, Response Text: %s", request_id, r.text)
# TODO pylint is right here... let's make it better.
except Exception: # pylint: disable=broad-except
pass
Expand Down
Loading