welpdev / mailchimp-bundle

MailChimp integration with Symfony and MailChimp API V3
https://welpdev.github.io/mailchimp-bundle/
MIT License
44 stars 36 forks source link

Notice: Undefined index: type #36

Open PetitGrigri opened 3 years ago

PetitGrigri commented 3 years ago

When a subscribed member from a list have been deleted from mailchimp (with "PERMANENTLY DELETE").

If you try to subscribe this member again, the mailchimp api response do not contain the "type" field.

e.g :

[
  "title" => "Forgotten Email Not Subscribed"
  "status" => 400
  "detail" => test@test.com was permanently deleted and cannot be re-imported. The contact must re-subscribe to get back on the list."
  "instance" => "9042d84b-3xc0-4b75-a7c7-f0efbx225328"
]

This causes an error in the "throwMailchimpError" method of the ListRepository" which expects this data :

    private function throwMailchimpError(array $errorResponse)
    {
        $errorArray = json_decode($errorResponse['body'], true);

        if (is_array($errorArray) && array_key_exists('errors', $errorArray)) {
            throw new MailchimpException(
                $errorArray['status'],
                $errorArray['detail'],
                $errorArray['type'],
                $errorArray['title'],
                $errorArray['errors'],
                $errorArray['instance']
            );
        } else {
            throw new MailchimpException(
                $errorArray['status'],
                $errorArray['detail'],
                $errorArray['type'],
                $errorArray['title'],
                null,
                $errorArray['instance']
            );
        }

This error occurs with the version 1.3.1.