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

Introduce new Idempotency error class #436

Merged
merged 1 commit into from
Feb 12, 2018
Merged

Conversation

ob-stripe
Copy link
Contributor

r? @brandur-stripe
cc @stripe/api-libraries

Adds support for the idempotency_error error type. Cf. stripe/stripe-ruby#613.

@@ -114,6 +116,9 @@ private static function _specificAPIError($rbody, $rcode, $rheaders, $resp, $err
if ($code == 'rate_limit') {
return new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders);
}
if ($type == 'idempotency_error') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry about the usual pedantry, but it kind of looks like the other conditional ladders for error interpretation in this file are alphabetized, and it might be worth giving this the same treatment. (Also, might want to change this to a switch like the others? It doesn't matter that much though.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean grouping rate_limit and idempotency_error in a switch statement? The problem with that is that the two values are in different variables ($code vs $type).

I've taken a look at how we handle this in other libraries: stripe-ruby completely dropped support for 400 rate_limit errors, which maybe we should do in other libraries as well, but that would be a breaking change and we just released 6.0.0 :/

stripe-python uses a series of semi-complex if statements: https://github.com/stripe/stripe-python/blob/master/stripe/api_requestor.py#L190-L214, but then again Python doesn't have switch.

I'm tempted to update the logic to something like stripe-python anyway, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, my mistake — I wasn't paying enough attention to notice the $code vs. $type distinction there. Feel free to leave it.

I'm tempted to update the logic to something like stripe-python anyway, wdyt?

IMO the logic ladders are at least pretty similar, and honestly PHP's is quite a bit more readable, so it might be okay to just leave as is. Up to you :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, let's leave it as is then. Thanks!

@brandur-stripe
Copy link
Contributor

Nice one @ob-stripe, and thanks for taking! My bad for not going through and adding these in when the server changes appeared.

@ob-stripe ob-stripe merged commit f73e405 into master Feb 12, 2018
@ob-stripe ob-stripe deleted the ob-idempotency-error branch February 12, 2018 19:46
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