-
Notifications
You must be signed in to change notification settings - Fork 22
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
fix(mailchimp): fatal error with invalid API keys #1690
base: trunk
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to complete the testing steps until I've emptied the cache (newspack_nl_mailchimp_cache_lists
option). With the wrong key, the list retrieval doesn't update the lists and fails silently, keeping the cached lists.
includes/service-providers/mailchimp/class-newspack-newsletters-mailchimp.php
Outdated
Show resolved
Hide resolved
@adekbadek aha, you're correct. 41db9b6 should fix this by returning a proper error in this scenario. So now, if you run |
…s-mailchimp.php Co-authored-by: Adam Cassis <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to complete the testing steps until I've emptied the cache (
newspack_nl_mailchimp_cache_lists
option). With the wrong key, the list retrieval doesn't update the lists and fails silently, keeping the cached lists.@adekbadek aha, you're correct. 41db9b6 should fix this by returning a proper error in this scenario. So now, if you run
wp cron event run newspack_nl_mailchimp_refresh_cache
or wait 20 minutes for the cache to refresh, the cached data will no longer be returned if we fail to refresh the cache, and the error message should appear in the UIs.
Wait! That's by design!
From the docs:
If the cache refresh fails, we will store the error in a separate option, and will only surface it to the user after 20 minutes.
In every admin page we will display a generic Warning message, telling the user to go to Newsletters > Settings to see the errors.
In Newsletters > Settings we will output the errors details.
Maybe what we can do is clear the cache if the API key changes
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #1690 +/- ##
============================================
- Coverage 20.38% 20.37% -0.02%
- Complexity 2664 2666 +2
============================================
Files 48 48
Lines 10619 10626 +7
============================================
Hits 2165 2165
- Misses 8454 8461 +7 ☔ View full report in Codecov by Sentry. |
Thanks for clarifying, @leogermani! I'll spin up another commit with that change |
All Submissions:
Changes proposed in this Pull Request:
Fixes a fatal error when trying to fetch audience/list data using an invalid Mailchimp API key. The fatal was happening because our Mailchimp integration's API response validation logic only considered status codes of
400
or404
to be errors, but an invalid API key error is returned with a status code of401
, and unhandled WP errors are returned with status codes of500
. So this PR will handle any response with a status code of400
or greater as an error.How to test the changes in this Pull Request:
trunk
, connect your site to Mailchimp using a valid API key.wp cron event run newspack_nl_mailchimp_refresh_cache
Other information: