toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
533 stars 100 forks source link

Raise HTTPError when HTTP requests fail #47

Closed dowski closed 4 years ago

dowski commented 4 years ago

When the statsapi.get method encounters a response code other than 200 or 201 it will raise a requests.exceptions.HTTPError. Previously it would raise a ValueError.

This should allow client code to more easily retry transient HTTP errors automatically.

This is an API change, so let me know if you'd like me to bump the version number too, or if you'd rather do that next time you release.

It also adds a test dependency on the responses library for setting up fake HTTP responses for requests. I think it more thorough exercises the code vs. mocking requests in this case and asserting that raise_for_status was called on the response. Let me know if you have any concerns about another test dependency though.

This is to resolve issue #46.

dowski commented 4 years ago

Thanks for the first round of review!

toddrob99 commented 4 years ago

Thank you very much for the thoughtful pull request. I am merging into my dev branch and then I will increment the version (actually going to bump to 1.0 since I think it's pretty stable) and release.

dowski commented 4 years ago

My pleasure! Thanks for the useful library!