nztim/mailchimp

Getting error messages in json

Closed this issue · 2 comments

Hi, I am using the below:
`try {
Mailchimp::subscribe('4171d6fa42', $email, ['FNAME' => $firstname, 'LNAME' => $lastname], false);
}
catch (Throwable $e)
{
dd($e->getMessage());

    }`

and the response is below:
""" Mailchimp API error (400): array (\n 'type' => 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/',\n 'title' => 'Invalid Resource',\n 'status' => 400,\n 'detail' => 'test@test.com looks fake or invalid, please enter a real email address.',\n 'instance' => '41e6b55c-3efa-449a-8dc9-4a8ebbf79d8c',\n ) """
can you please advise on how I can get this as a json response?

Thanks

nztim commented

I've added a response() method to MailchimpBadRequestException, please update to v3.6 and try this:

try {
    Mailchimp::subscribe('4171d6fa42', $email, ['FNAME' => $firstname, 'LNAME' => $lastname], false);
} catch (Throwable $e) {
    dd($e->response());
}

Let me know what you think.

Excellent, that has worked a treat mate.

Thanks