Skip to content

Conversation

@prijendev
Copy link
Contributor

Description of change

  • Reading error code from response.status_code attribute.
  • Show error_description in an error message if available in response.
  • A written unit test case for the same.

Manual QA steps

  • Set invalid client_id or refresh_token and raise the error.
  • Verify that tap should raise a proper error instead of AttributeError: 'str' object has no attribute 'get'

Risks

Rollback steps

  • revert this branch

@prijendev prijendev changed the title Initial commit TDL-16827-str-object-has-no-attribute-get Dec 14, 2021
@prijendev prijendev changed the title TDL-16827-str-object-has-no-attribute-get TDL-16827 'str' object has no attribute 'get' Dec 14, 2021
Copy link
Contributor

@KrisPersonal KrisPersonal left a comment

Choose a reason for hiding this comment

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

When making any change to the code please comment the code. Why the code is changed and what was changed?

# There is nothing we can do here since Google has neither sent
# us a 2xx response nor a response content.
return
status_code = response.status_code # Get status code of the response
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the previous, it was trying to get status code from error.code of JSON response. But in many responses, the value of the error key is just a string. So, it was throwing AttributeError: 'str' object has no attribute 'get' because of error.code missing in response. So, here we are retrieving the status code from the response object itself.

response.get('message', 'Unknown Error'))
error_code = response.get('error', {}).get('code')
ex = get_exception_for_error_code(error_code)
message = 'HTTP-error-code: %s %s: %s' % (status_code, response.get('error', str(error)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In previous, if 'message' does not found in JSON response then it was showing directly Unknown Error in the error message. But, we observed that in many responses error_description comes as a detailed cause of the error. So, here we added an extra check for error_description to better readability. If error_description also does not found then it shows Unknown Error.

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.

6 participants