-
Notifications
You must be signed in to change notification settings - Fork 732
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
Add error handling, fix broken unit tests #260
Open
bpross
wants to merge
11
commits into
danpaquin:master
Choose a base branch
from
bpross:add-error-handling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
67ba3fe
Added error handling. Added tests. Added requirements. Fixed tests
bpross aec89f3
Added README info, added self to contributors, bumped version
bpross bc3044d
Fixed README formatting
bpross 8690c15
Fixed typo
bpross f328a6f
Fixed small things found in PR
bpross 932c613
Use PSL defined HTTP codes
bpross ce036ce
Fixed issue with message -> code. added rate limit exception and tset
bpross 1025c3d
Remove raise for status
bpross 304f106
update readme
bpross e0467b1
Remove third blank line
bpross 6d020e7
Rebased with master and updated everything to be CBPRO instead of GDA…
bpross File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
class CbproException(Exception): | ||
""" | ||
Base Coinbase Pro Exception | ||
Raised when Bad Response returned from Coinbase Pro | ||
See: https://docs.pro.coinbase.com/?r=1#errors | ||
""" | ||
|
||
def __init__(self, message, code): | ||
""" | ||
:param message: Message from Coinbase Pro response | ||
:type message: str | ||
:param code: HTTP Code | ||
:type code: int | ||
""" | ||
self._message = message | ||
self._code = code | ||
|
||
@property | ||
def message(self): | ||
return self._message | ||
|
||
@message.setter | ||
def message(self, message): | ||
self._message = message | ||
|
||
@property | ||
def code(self): | ||
return self._code | ||
|
||
@message.setter | ||
def code(self, code): | ||
self._code = code | ||
|
||
|
||
class InvalidCbproRequest(CbproException): | ||
""" | ||
Raised on 400 response from Coinbase Pro | ||
""" | ||
pass | ||
|
||
|
||
class UnauthorizedCbproRequest(CbproException): | ||
""" | ||
Raised on 401 response from Coinbase Pro | ||
""" | ||
pass | ||
|
||
|
||
class ForbiddenCbproRequest(CbproException): | ||
""" | ||
Raised on 403 response from Coinbase Pro | ||
""" | ||
pass | ||
|
||
|
||
class NotFoundCbproRequest(CbproException): | ||
""" | ||
Raised on 404 response from Coinbase Pro | ||
""" | ||
pass | ||
|
||
|
||
class CbproRateLimitRequest(CbproException): | ||
""" | ||
Raised on 429 response from Coinbase Pro | ||
""" | ||
pass | ||
|
||
|
||
class UnknownCbproClientRequest(CbproException): | ||
""" | ||
Raised on 4XX responses not tracked | ||
""" | ||
pass | ||
|
||
|
||
class InternalErrorCbproRequest(CbproException): | ||
""" | ||
Raised on 500 response from Coinbase Pro | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ Leonard Lin | |
Jeff Gibson | ||
David Caseria | ||
Paul Mestemaker | ||
Drew Rice | ||
Drew Rice | ||
Benjamin Ross |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
|
||
setup( | ||
name='cbpro', | ||
version='1.1.4', | ||
version='2.0.0', | ||
author='Daniel Paquin', | ||
author_email='[email protected]', | ||
license='MIT', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from unittest.mock import patch | ||
import pytest | ||
import cbpro | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
return cbpro.PublicClient() | ||
|
||
|
||
@pytest.mark.parametrize("code, exception",[ | ||
(400, cbpro.exceptions.InvalidCbproRequest), | ||
(401, cbpro.exceptions.UnauthorizedCbproRequest), | ||
(403, cbpro.exceptions.ForbiddenCbproRequest), | ||
(404, cbpro.exceptions.NotFoundCbproRequest), | ||
(422, cbpro.exceptions.UnknownCbproClientRequest), | ||
(429, cbpro.exceptions.CbproRateLimitRequest), | ||
(500, cbpro.exceptions.InternalErrorCbproRequest)]) | ||
@patch('requests.Session.request') | ||
def test_cbpro_exceptions(mock_request, client, code, exception): | ||
mock_request.return_value.status_code = code | ||
with pytest.raises(exception): | ||
response = client.get_products() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you bumping the version to 2.0, is it not backwards compatible anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not backwards compatible, as it will raise exceptions instead of returning a response object.