Skip to content

Commit

Permalink
Merge pull request #72 from collective/maurits-catch-errors-again
Browse files Browse the repository at this point in the history
More often catch errors contacting MailChimp.
  • Loading branch information
mauritsvanrees authored Jun 21, 2024
2 parents f003a5d + cf1c835 commit 9af0a3e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Changelog
4.0.0a3 (unreleased)
--------------------

- Nothing changed yet.
- More often catch errors contacting MailChimp.
Catch errors in vocabularies, otherwise the subscribe form not even shows up.
Catch errors updating the cache, otherwise the controlpanel gives an error,
preventing a chance to fix it.
[maurits]


4.0.0a2 (2024-06-21)
Expand Down
16 changes: 14 additions & 2 deletions src/collective/mailchimp/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
from plone.app.registry.browser import controlpanel
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.Five.browser import BrowserView
from Products.statusmessages.interfaces import IStatusMessage
from z3c.form.interfaces import WidgetActionExecutionError
from zope.component import getUtility
from zope.interface import alsoProvides
from zope.interface import Invalid

import logging


logger = logging.getLogger(__name__)

try:
from plone.protect.interfaces import IDisableCSRFProtection
Expand Down Expand Up @@ -40,8 +45,15 @@ def updateCache(self):
if IDisableCSRFProtection is not None:
alsoProvides(self.request, IDisableCSRFProtection)
mailchimp = getUtility(IMailchimpLocator)
mailchimp.updateCache()

try:
mailchimp.updateCache()
except Exception as exc:
# Do not break completely, otherwise the controlpanel fails to load.
logger.warn(exc)
IStatusMessage(self.request).addStatusMessage(
f"Error contacting MailChimp: {exc}",
type="error",
)

class MailchimpSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
form = MailchimpSettingsEditForm
Expand Down
15 changes: 13 additions & 2 deletions src/collective/mailchimp/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

def available_lists(context):
mailchimp = getUtility(IMailchimpLocator)
lists = mailchimp.lists()
try:
lists = mailchimp.lists()
except Exception as exc:
# Do not break completely, otherwise forms fail to load.
logger.warn(exc)
lists = []
if not lists:
return SimpleVocabulary([])
return SimpleVocabulary(
Expand All @@ -28,7 +33,13 @@ def interest_groups(context):
list_id = mailchimp.default_list_id()
if not list_id:
return SimpleVocabulary([])
groups = mailchimp.groups(list_id=list_id)
try:
groups = mailchimp.groups(list_id=list_id)
except Exception as exc:
# Do not break completely, otherwise forms fail to load.
logger.warn(exc)
groups = []

if not groups:
return SimpleVocabulary([])
# Each category has a list of options/groups/interests. We only support
Expand Down

0 comments on commit 9af0a3e

Please sign in to comment.