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

Mailchimp API connection error handling #2247

Open
miguelpeixe opened this issue Jan 23, 2023 · 0 comments
Open

Mailchimp API connection error handling #2247

miguelpeixe opened this issue Jan 23, 2023 · 0 comments
Assignees
Labels

Comments

@miguelpeixe
Copy link
Member

It's not always guaranteed that the response body from Mailchimp is an array, as assumed here:

$parsed_response = json_decode( $response['body'], true );
return new \WP_Error(
'newspack_mailchimp_api',
array_key_exists( 'title', $parsed_response ) ? $parsed_response['title'] : __( 'Request failed.', 'newspack' )
);

It can fail with:

PHP Fatal error:  Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in newspack-plugin/includes/oauth/class-mailchimp-api.php:171

A more generic error handling is suited for when the response body is unavailable.

@miguelpeixe miguelpeixe self-assigned this Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant