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

Updated exception event listener #15

Closed
wants to merge 3 commits into from

Conversation

slavafomin
Copy link

Updated exception event listener to better represent desired logic and handle edge scenarios like encountered here: #14

Probably we should also update unit tests.

Slava Fomin added 2 commits March 19, 2014 03:54
Updated exception event listener to better represent desired logic and handle edge scenarios like encountered here: zf-fr#14
Updated method's DocBlock throws statement.

$result = json_decode($response->getBody(), true);
$errorName = isset($result['name']) ? $result['name'] : 'Unknown_Exception';
if (
Copy link
Member

Choose a reason for hiding this comment

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

This does not follow PSR, please write:

// All MailChimp error responses have a body and non-200 HTTP code
if (null !== $response && 200 !== $response->getStatusCode()) {

}

@bakura10
Copy link
Member

Also, Travis is not configured for MailChimp, but please make sure all the tests run.

@slavafomin
Copy link
Author

The idea behind this code is that we can't just trust third party service in respect to returned values. Even MailChimp is not protected from errors. So it's a good idea to check every possible scenario. This way program will be more stable and reliable. I don't see any harm in doing more checks. More checks is better than less. And there is no performance issue here.

This approach sometimes called a defensive programming.

@bakura10
Copy link
Member

This is not being defensive, this is making the code harder to read than it needs. Honestly I've never in my life checked if the json was properly decoded. This cannot fail, and even if it failed, this is such an extreme rare case (and would likely be because of MailChimp), that hard fail is not really a problem.

if (null !== $response && 200 !== $response->getStatusCode()) {
// MailChimp body is in JSON, decoding it.
$result = json_decode($response->getBody(), true);
if (JSON_ERROR_NONE !== json_last_error() || !is_array($result)) {
Copy link
Member

Choose a reason for hiding this comment

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

So please remove this, it's not needed and cannot happen.

@bakura10
Copy link
Member

Does my feedback makes sense?

@slavafomin
Copy link
Author

Hey @bakura10!
I'm sorry I have no time right now to dive into this problem, but considering number of issues you have with my code, you probably should better re-introduce necessary changes from scratch.
Let's just think about this pull-request as a demonstration of ideas.
Thank you!

@bakura10
Copy link
Member

Thanks. I have no time for it neither until next wednesday, 'ill do that later :). Please ping me if I forget, and thanks for your contribution ;).

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