-
Notifications
You must be signed in to change notification settings - Fork 161
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
Correctly throw an exception when handing a text response #92
Correctly throw an exception when handing a text response #92
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! 👋 I left you a few comments. Please add the remaining tests.
auth0/v3/authentication/base.py
Outdated
try: | ||
text = json.loads(response.text) if response.text else {} | ||
result = json.loads(response.text) if response.text else {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result
is the "original" error response body?
auth0/v3/authentication/base.py
Outdated
try: | ||
text = json.loads(response.text) if response.text else {} | ||
result = json.loads(response.text) if response.text else {} | ||
error_code = result.get('error', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen some error responses return code
instead of error
. Both meaning the same thing. If this value is not present I'd anyway set something like "a0.sdk.internal.unknown"
.
auth0/v3/authentication/base.py
Outdated
message=text.get('error_description', '')) | ||
return text | ||
result = response.text | ||
error_code = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd set something like "a0.sdk.internal.plain"
Previously the text of the response was always returned if it could not be interpreted as JSON.
866c726
to
3033634
Compare
@lbalmaceda I've addressed your comments. I ended up rewriting it completely because I didn't like the overlapping logic. Maybe seems a bit over-engineered now, but at least it's clear what's going on in each case. See what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since python is not my main language I don't know how pythonish this code is. But it looks good and I'm OK with the changes. Thanks 🌮
@cocojoe Go ahead ⚡️
@benbc I had one question regarding the response, could you provide a sample of when you are receiving a plan text response for a |
@lbalmaceda I've ran tests locally, is OK |
@cocojoe I'm afraid I don't know what that means. |
I think what @cocojoe wants is a real example on when a response would be of type "plain text" like the one tested here. I asked @benbc to add it because some endpoints return plain text such as this one (check the sample response on the right). If this doesn't apply to this SDK feel free to remove it. |
@cocojoe @lbalmaceda I'm afraid I don't know what to do here. We see an occasional problem in our running system where Auth0 returns a plain text error reponse and the library treats it as non-error. I've fixed that here because the bug was obvious. But I have no knowledge of the Auth0 APIs. If you can tell me exactly what test you want me to add then I can do it. But otherwise I'm just going to have to leave this proposed fix in your hands and hope you can make something of it. |
@benbc Sorry, I should have perhaps been more clear. In your original description you mentioned that this happened when you were calling |
@cocojoe I'm afraid I don't have an example of this to hand. It hasn't happened for a few weeks. |
@cocojoe like I said, I'm OK with the changes. Can we please merge this one so we can have a clearer diff on the other error parsing fixing PRs? |
@cocojoe We've just seen another of these errors. It was thrown from
|
@benbc thanks for reporting. |
Hello. We've seen this problem in our running system when calling
GetToken.client_credentials()
. We currently have to parse the response text to see if it looks like an error message rather than a token.