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

Print error when API provides an error. #20

Merged
merged 2 commits into from
Feb 3, 2025
Merged

Conversation

YumYummity
Copy link
Contributor

This change just makes the function print the error provided by the API.

Sometimes, this can be useful (eg. 403 can have many reasons, and sometimes the API provides a clear reason).

if 400 <= resp.status_code < 600:
try: # print the error message provided by the API.
self.response_to_dict(resp)
print(resp)
Copy link
Owner

Choose a reason for hiding this comment

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

Please use logger.warn("%s" % resp) for error reporting facilities since that's how the rest of AbCache did things

self.response_to_dict(resp)
print(resp)
except:
print(resp)
Copy link
Owner

Choose a reason for hiding this comment

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

Same goes here.
Also it might be a good idea to handle special cases like 503s since this might have no response body - and in that case, it's usally the server doing maintenance work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

503 should be returning
{
"errorCode": "maintenance",
"errorMessage": "",
"httpStatus": 503
}

This doesn't print the errorMessage, just the entire response JSON

@mos9527
Copy link
Owner

mos9527 commented Feb 3, 2025

LGTM. Thanks again for the PR! Merging now

@mos9527 mos9527 merged commit a21b7f1 into mos9527:main Feb 3, 2025
1 of 2 checks passed
mos9527 added a commit that referenced this pull request Feb 3, 2025
AbCache: Print error when API provides an error. #20
@YumYummity
Copy link
Contributor Author

@mos9527 there was an issue in the PR code; the line after the "except:" should be resp.content and not resp, since that isn't decoded.

@mos9527
Copy link
Owner

mos9527 commented Feb 3, 2025

@YumYummity Made the change here: 0e4a745
Sorry for the oversight. Looks like logger.warn is deprecated too - which has now been changed to logger.warning
For its actual severity - logger level has been changed to logger.error here as well.

mos9527 added a commit that referenced this pull request Feb 3, 2025
AbCache: Actually print bad response's content. #20
@YumYummity
Copy link
Contributor Author

Thank you! LGTM

@YumYummity
Copy link
Contributor Author

@mos9527 on second thought, doesn't LGTM 💀

Sorry, the self.response_to_dict is called but we are still printing resp.content despite converting it to a dict.

mos9527 added a commit that referenced this pull request Feb 4, 2025
AbCache: Actually print bad response's content. Again. #20
@mos9527
Copy link
Owner

mos9527 commented Feb 4, 2025

Fixed in 8b3eda0
Took 3 patches to get this right💀.. I should banish myself to the shadow realm

@YumYummity
Copy link
Contributor Author

Don't worry, coding is hard LOL

LGTM now.

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