Skip to content

Commit

Permalink
Merge pull request #2670 from justcarakas/mailmotor-spam-errors
Browse files Browse the repository at this point in the history
Catch mailmotor spamming errors
  • Loading branch information
carakas committed Dec 19, 2018
2 parents 17d2d8a + e2be86d commit 0de560c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Frontend/Modules/Mailmotor/Actions/Subscribe.php
Expand Up @@ -2,6 +2,7 @@

namespace Frontend\Modules\Mailmotor\Actions;

use Exception;
use Frontend\Core\Engine\Base\Block as FrontendBaseBlock;
use Frontend\Core\Engine\Navigation as FrontendNavigation;
use Frontend\Core\Language\Locale;
Expand Down Expand Up @@ -61,6 +62,22 @@ public function execute(): void
);

$doubleOptIn = false;
} catch (Exception $exception) {
$reason = json_decode($exception->getMessage());
// check if the error is one from mailchimp
if ($reason === false) {
throw $exception;
}

$this->getContainer()->get('logger')->error('Mailmotor Subcribe Mailchimp error: ' . $reason);

$this->template->assign('mailmotorSubscribeHasFormError', true);
$this->template->assign('form', $form->createView());

$this->loadTemplate();
$this->parse();

return;
}

$redirectLink .= '&double-opt-in=';
Expand Down
15 changes: 15 additions & 0 deletions src/Frontend/Modules/Mailmotor/Actions/Unsubscribe.php
Expand Up @@ -2,6 +2,7 @@

namespace Frontend\Modules\Mailmotor\Actions;

use Exception;
use Frontend\Core\Engine\Base\Block as FrontendBaseBlock;
use Frontend\Core\Engine\Navigation as FrontendNavigation;
use Frontend\Core\Language\Locale;
Expand Down Expand Up @@ -51,6 +52,20 @@ public function execute(): void
NotImplementedUnsubscribedEvent::EVENT_NAME,
new NotImplementedUnsubscribedEvent($unsubscription)
);
} catch (Exception $exception) {
$reason = json_decode($exception->getMessage());
// check if the error is one from mailchimp
if ($reason === false) {
throw $exception;
}

$this->template->assign('mailmotorUnsubscribeHasFormError', true);
$this->template->assign('form', $form->createView());

$this->loadTemplate();
$this->parse();

return;
}

$this->redirect(
Expand Down

0 comments on commit 0de560c

Please sign in to comment.