Skip to content

[improvement] Include TraceID in the message for HTTPError #21

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

Closed
wants to merge 2 commits into from
Closed

[improvement] Include TraceID in the message for HTTPError #21

wants to merge 2 commits into from

Conversation

JacekLach
Copy link
Contributor

Python errors are, more than any others, printed out to interactive consoles rather than logged with context.
Including the traceid in the printout is going to help a bunch in debugging issues in interactive workflows.

Python errors are, more than any others, printed out to interactive consoles rather than logged with context.
Including the traceid in the printout is going to help a bunch in debugging issues in interactive workflows.
detail.get('errorName', 'UnknownError'),
detail.get('message', 'No Message'),
e.response.headers.get('X-B3-TraceId', 'No TraceId'),
Copy link

Choose a reason for hiding this comment

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

e.response.headers is guaranteed to exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh no I guess response can be None sometimes

@@ -81,12 +81,14 @@ def _request(self, *args, **kwargs):
detail = e.response.json()
except ValueError:
detail = {'message': e.response.content}
detail['traceId'] = e.response.headers.get('X-B3-TraceId'),
else:
detail = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kinda feel like if response is None, we should just reraise the old error (e)

Copy link

Choose a reason for hiding this comment

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

I agree we should just pass along the original HttpError in that case.

I think it might be nice to wrap the HTTPError in a way that python (3.x) can understand a little better (i.e. use from future.utils import raise_from), and perhaps have a new ConjureHttpError type that has a reference to its cause as well as attributes for each of the details that can be present in an httpremoting failure response.

ahggns pushed a commit that referenced this pull request Oct 17, 2018
…or details (#22)

<!-- PR title should start with '[fix]', '[improvement]' or '[break]' if this PR would cause a patch, minor or major SemVer bump. Omit the prefix if this PR doesn't warrant a standalone release. -->

## Before this PR
<!-- Describe the problem you encountered with the current state of the world (or link to an issue) and why it's important to fix now. -->
`HTTPError` response content was parsed hoping to find `SerializableError` contents, though didn't extract all contents and relied on deprecated fields such as message. The original `HTTPError` and a message were then wrapped in a new `HTTPError` and reraised.

## After this PR
<!-- Describe at a high-level why this approach is better. -->
1. The original `HTTPError` is wrapped in a way (`raise_from`) that is understandable to Python 3's improved traceback functionality.
2. The new `ConjureHTTPError` can be separately detected as such while maintaining a reference to its wrapped `cause`.
3. The new `ConjureHTTPError` contains attributes to access fields from `SerializableError`, as well as the `X-B3-TraceId` from response headers when possible.

<!-- Reference any existing GitHub issues, e.g. 'fixes #000' or 'relevant to #000' -->
See also #21.
@ahggns
Copy link

ahggns commented Oct 17, 2018

Closing in favor of #22

@ahggns ahggns closed this Oct 17, 2018
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.

2 participants