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

getStatusCode() exception #14

Open
slavafomin opened this issue Mar 18, 2014 · 25 comments
Open

getStatusCode() exception #14

slavafomin opened this issue Mar 18, 2014 · 25 comments

Comments

@slavafomin
Copy link

Hey Michaël!

I'm getting this weird exception:

PHP Fatal error:  Call to a member function getStatusCode() on a non-object in /vagrant/vendor/zfr/zfr-mailchimp/src/ZfrMailChimp/Client/Listener/ErrorHandlerListener.php on line 145

Can you elaborate please? Thanks!

@bakura10
Copy link
Member

Hhm... That's strange. It seems that the response is not properly created into the guzzle event. How do you get this error? Which method are you calling so that I can try to reproduce the issue?

@slavafomin
Copy link
Author

Here's my versions:

guzzle/guzzle                       v3.8.1
zfr/zfr-mailchimp-bundle            v2.0.0
zfr/zfr-mailchimp                   v2.0.2

I'm using subscribe method.

@bakura10
Copy link
Member

But are you trying to use this listener yourself? It's not meant to be used by you. Only the client automatically register this listener. You should not subscribe yourself. What are you trying to do exactly?

@slavafomin
Copy link
Author

I'm not using the listener myself. My subscription code just broke for some reason with this exception.

@bakura10
Copy link
Member

I've double checked the service descriptor and it seems right. Does it fail with other methods or only "subscribe" ?

@slavafomin
Copy link
Author

It looks like it's failing with other methods as well.

@bakura10
Copy link
Member

Gosh. That's annoying. I checked the Guzzle change log and no BC seems to have been done. Can you try to forcing an older version of Guzzle into your composer.json (like 3.7)? I have not touched ZfrMailchimp so it's either a problem on MailChimp that caused the client to throw a strange exception, or a change in Guzzle (they have already done BC in minor version, that's annoying).

@bakura10
Copy link
Member

This seems related to Guzzle: guzzle/guzzle#589

@bakura10
Copy link
Member

Are you using PHP 5.3.3 ?

@slavafomin
Copy link
Author

$ php --version
PHP 5.5.3-1ubuntu2.2 (cli) (built: Feb 28 2014 20:06:05) 

@bakura10
Copy link
Member

Grrr. Please try what I told you (testing with older version of guzzle)

@slavafomin
Copy link
Author

I've just tried to use Guzzle v3.7.4 and v3.5.0. No joy. Weird.

@bakura10
Copy link
Member

Wow. That's really strange. I cannot explain it to myself :'(. I'll try tomorrow if I can replicate the issue.

@bakura10
Copy link
Member

@univate, as you seems to use ZfrMailChimp, did you encounter any issue?

@slavafomin
Copy link
Author

OK. Thank you @bakura10 for a quick reply as always.

But, is it possible that something can interfere with Guzzle and/or ZfrMailChimp? Maybe another package or something?

@bakura10
Copy link
Member

Hmmm I can't see exactly what could interfere :/.

@bakura10
Copy link
Member

If you comment that line (https://github.com/zf-fr/zfr-mailchimp/blob/master/src/ZfrMailChimp/Client/MailChimpClient.php#L178), so that the subscriber is no longer attached, does it work or does it trigger another error?

@slavafomin
Copy link
Author

Gotcha!

[Guzzle\Http\Exception\CurlException]                                                                                   
[curl] 6: Could not resolve host: key.api.mailchimp.com [url] https://key.api.mailchimp.com/2.0/lists/member-info.json

How stupid of me. Looks like configuration file were reverted to default values and it caused to use incorrect API key. Sorry, I should have more properly checked my application logic first. Looks like I need a good sleep ))

Maybe it is an opportunity to improve listener logic by the way?

@bakura10
Copy link
Member

Ouf ! Good news.

What do you want to improve about listener logic? Adding a test to check if the response exist ? I'm not sure this bring any improvement though.

@slavafomin
Copy link
Author

In this case it was hiding the real problem (original exception). Maybe there is a way to distinguish between MailChimp (domain related) errors vs. core one (cURL etc).

I think ideally, it should detect errors from MailChimp and throw related exceptions. In other cases it should not alter behavior in any way.

@bakura10
Copy link
Member

Ok. Can you inspect if the $event (https://github.com/zf-fr/zfr-mailchimp/blob/master/src/ZfrMailChimp/Client/Listener/ErrorHandlerListener.php#L143) contains an 'exception' property or something? What we could do is something like that :

public function handleError(Event $event)
    {
        $response = $event['response'];

        if ($response->getStatusCode() === 200) {
            return;
        }

        $result    = json_decode($response->getBody(), true);
        $errorName = isset($result['name']) ? $result['name'] : null;

        if (null === $errorName) {
            // Not a MailChimp exception
            return or throw $event['exception'];
        }

        throw new $this->errorMap[$errorName]($result['error'], $result['code']);
    }

I don't exactly remember how this object is formed.

@slavafomin
Copy link
Author

I will try to figure that out and submit a pull-request then )
Thanks for your time again )

@univate
Copy link
Contributor

univate commented Mar 19, 2014

I haven't come across this error - using the latest code here in production.

I am not using the zfr-mailchimp-bundle, I am using an older version of guzzle - 3.7.4

slavafomin pushed a commit to slavafomin/zfr-mailchimp that referenced this issue Mar 19, 2014
Updated exception event listener to better represent desired logic and handle edge scenarios like encountered here: zf-fr#14
@jhkchan
Copy link

jhkchan commented Apr 16, 2014

if async is set, response will be null, so #15 would fix it.

@bakura10
Copy link
Member

Hi. Ok, I will do that now.

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

No branches or pull requests

4 participants