Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ErrorObject to StripeError exceptions
- Loading branch information
Showing
7 changed files
with
117 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
from stripe.util import merge_dicts | ||
from stripe.stripe_object import StripeObject | ||
|
||
|
||
class ErrorObject(StripeObject): | ||
def refresh_from( | ||
self, | ||
values, | ||
api_key=None, | ||
partial=False, | ||
stripe_version=None, | ||
stripe_account=None, | ||
last_response=None, | ||
): | ||
# Unlike most other API resources, the API will omit attributes in | ||
# error objects when they have a null value. We manually set default | ||
# values here to facilitate generic error handling. | ||
values = merge_dicts( | ||
{ | ||
"charge": None, | ||
"code": None, | ||
"decline_code": None, | ||
"doc_url": None, | ||
"message": None, | ||
"param": None, | ||
"payment_intent": None, | ||
"payment_method": None, | ||
"setup_intent": None, | ||
"source": None, | ||
"type": None, | ||
}, | ||
values, | ||
) | ||
return super(ErrorObject, self).refresh_from( | ||
values, | ||
api_key, | ||
partial, | ||
stripe_version, | ||
stripe_account, | ||
last_response, | ||
) | ||
|
||
|
||
class OAuthErrorObject(StripeObject): | ||
def refresh_from( | ||
self, | ||
values, | ||
api_key=None, | ||
partial=False, | ||
stripe_version=None, | ||
stripe_account=None, | ||
last_response=None, | ||
): | ||
# Unlike most other API resources, the API will omit attributes in | ||
# error objects when they have a null value. We manually set default | ||
# values here to facilitate generic error handling. | ||
values = merge_dicts( | ||
{"error": None, "error_description": None}, values | ||
) | ||
return super(OAuthErrorObject, self).refresh_from( | ||
values, | ||
api_key, | ||
partial, | ||
stripe_version, | ||
stripe_account, | ||
last_response, | ||
) |
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
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,14 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
from stripe import oauth_error | ||
|
||
|
||
class TestOAuthError(object): | ||
def test_error_object(self): | ||
err = oauth_error.OAuthError( | ||
"message", "description", json_body={"error": "some_oauth_error"} | ||
) | ||
assert err.error is not None | ||
assert err.error.error == "some_oauth_error" |