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

Fix empty body issue when GET fails #282

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

germanop
Copy link

@germanop germanop commented Sep 13, 2024

If GET fails, the body is empty, so an attempt to convert the body to JSON raises an exception.

The solution here is to return a valid empty JSON body to the caller, that might expect a valid JSON.

This problem has been tackled in other places (but not in set_user_role nor set_grafana_put) in different ways.

  • get_grafana_version does not attempt anything if status is not 200
  • log_response catches ValueError exceptions and then logs r.text (fine, because print can handle None)
  • set_grafana_post catches ValueError and then returns r.text.

I did not go for the same approach as set_grafana_post because I believe the caller should always receive a valid JSON.

When a GET fails the body is empty, so a following attempt to
convert the body to json fails.
Now, if GET fails we return an empty json, given the caller may expect
a valid json.
@mt3593 mt3593 mentioned this pull request Dec 17, 2024
@mt3593
Copy link
Contributor

mt3593 commented Dec 17, 2024

@abalalaev or anyone else, any chance of getting this merged?

@mt3593
Copy link
Contributor

mt3593 commented Dec 17, 2024

Also #279 appears to fix the same bug linked to issue #277

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