Uh oh!
There was an error while loading. Please reload this page.
fix a potential json parsing error - #485
Conversation
ziliangpeng
commented
Apr 7, 2020
georgysavva
commented
Apr 7, 2020
Why not to just move |
ziliangpeng
commented
Apr 8, 2020
@georgysavva The decoded json needs to be used in the error handling as well as being a return value. I believe keeping it here is the most appropriate place to decode it. Where else exactly do you see is a better place? |
alvyjudy
commented
May 4, 2020
Hi, please correct me if I'm wrong but it appears that this problem (response not in json format) kind of occur by chance? (I get this impression after reading the discussion you mentioned) So when it arises wouldn't it be a better idea to re-fetch, rather than giving the error back to the client? I would imagine the error message to be quite obscure. Also, if it is indeed the API that wouldn't return a json response, would it be better to place your proposed functionality inside |
| response_data = json.loads(response_body) | ||
| try: | ||
| response_data = json.loads(response_body) | ||
| except (KeyError, ValueError): |
There was a problem hiding this comment.
| except(KeyError, ValueError): | |
| exceptjson.DecodeError: |
WDYT?
There was a problem hiding this comment.
That would be a Python3-only change, i think.
tseaver
left a comment
There was a problem hiding this comment.
Rather than doing remapping of the error twice (once above and once below the check of response.status, it would be better to move the parsing inside the block for an OK status. E.g.:
ifresponse.status==http_client.OK:
returnjson.loads(response_body)
ifresponse.content_type!="application/json":
error_details=response_bodyraiseexceptions.RefreshError(error_details, response_body)
response_data=json.decode(response_body)
error_desc=response_data.get("error_description") or""error_code=response_data.get("error") or""if (
any(e=="internal_failure"forein (error_code, error_desc))
andretry<1
):
retry+=1continue_handle_error_response(response_body)parthea
commented
Aug 14, 2021
Hi @ziliangpeng , I'm going to close this PR due to inactivity but please feel free to re-open it. |
As discussed here, there's a chance (which I have experienced) that the response of the oauth request is not in json format, resulting in json parsing error.
This PR fixes it by capturing the exception and convert to a
RefreshError.