Problem with catching error
Closed this issue · 1 comments
Hello, I cant catch any error which is Thrown.
In main log, i have error, but it stops everything and dont go to next step.
My code:
try { Mailchimp::addUpdateMember('code....', $member); } catch (Throwable $e) { $this->logger->info('Błąd adresu email: '$e->getMessage() ); }
Error:
[2019-04-18 11:44:47] local.ERROR: Mailchimp API error (400): array (
'type' => 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/',
'title' => 'Member In Compliance State',
'status' => 400,
'detail' => 'something@gmail.com is in a compliance state due to unsubscribe, bounce, or compliance review and cannot be subscribed.',
'instance' => 'code',
) {"exception":"[object] (NZTim\Mailchimp\Exception\MailchimpBadRequestException(code: 400): Mailchimp API error (400): array (
'type' => 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/',
'title' => 'Member In Compliance State',
'status' => 400,
'detail' => 'somethinh@gmail.com is in a compliance state due to unsubscribe, bounce, or compliance review and cannot be subscribed.',
'instance' => 'code',
) at C:\xampp\_panel\vendor
ztim\mailchimp\src\MailchimpApi.php:111)
I know that emial is unsubscribed and I want to get an error, check it and unsubscribe this email from main datebase.
So my question is, why try, catch dont work and stops everything, and how i can get en error code to remove email from my db.
Thanks
Here is my test which works correctly:
<?php
require 'vendor/autoload.php';
$mc = new NZTim\Mailchimp\Mailchimp('invalid-us2');
$member = new NZTim\Mailchimp\Member('test@example.com');
try {
$mc->addUpdateMember('invalid', $member);
} catch (Throwable $e) {
echo "Caught!\n" . $e->getMessage();
}
So I don't see an error in the code you posted. The first thing that comes to mind is to check that Throwable is imported correctly. Beyond that I'm not sure, if you show me more or link to a repo I could take a look.
Edit: yes I bet that's it, try \Throwable
and see if there is a change.