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 JSON decode error when parsing error response in client #35

Merged
merged 4 commits into from Dec 9, 2021

Conversation

chadawagner
Copy link
Contributor

No description provided.

@ofpiyush
Copy link
Contributor

Hi, sorry for the delay on this.

Thanks for the PR!

The core maintainer for this project isn't available right now.

I'll review and approve/ask for changes if you're ok with making additional changes.

Once he finds some time, he can merge this in and make a new release.

@avinassh
Copy link
Contributor

Thank you @ofpiyush for stepping in. If approved, I will be happy to merge.

Copy link
Contributor

@ofpiyush ofpiyush left a comment

Choose a reason for hiding this comment

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

@chadawagner Sorry for the delay again, I finally found some time to review. Thanks for the PR again :)

There's a minor bug in the code, could you make the changes to fix the issue?

twirp/client.py Outdated
raise exceptions.TwirpServerException.from_json(resp.json())
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

This will always catch the exception. Including exceptions.TwirpServerException

As a result, we will always only get either Unavailable or Unknown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I was catching the specific error in my local patch, not sure how I missed adding it to the PR. Fixed it, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks it seems to work now!

twirp/client.py Outdated
else:
code = errors.Errors.Unknown
raise exceptions.TwirpServerException(
code=code, message=resp.text
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be worth adding the original status code and headers to the meta dict here? And is it ok to assume that resp.text can be sent as message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For context: the problem I ran into was that an intermediate load balancer was returning a 503 response with an HTML body, but all we were seeing was the JSONDecodeError. We were able to diagnose the actual source of the error only after surfacing the status, headers, and body of the actual response.

Copy link
Contributor

@ofpiyush ofpiyush Nov 21, 2021

Choose a reason for hiding this comment

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

Maybe we should send standard text message and meta.status_code and meta.body

https://twitchtv.github.io/twirp/docs/errors.html#http-errors-from-intermediary-proxies

Check this out!

Copy link
Contributor

Choose a reason for hiding this comment

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

More generally, we should try to follow the go package as closely as possible.

https://github.com/twitchtv/twirp/blob/main/protoc-gen-twirp/generator.go#L635-L664

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree, I can add to this PR or would that warrant a new one

Copy link
Contributor

Choose a reason for hiding this comment

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

You can add to this one 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ofpiyush done!

@avinassh avinassh merged commit 53ca044 into verloop:main Dec 9, 2021
@avinassh
Copy link
Contributor

avinassh commented Dec 9, 2021

Thank you @chadawagner and @ofpiyush!

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.

None yet

3 participants