Skip to content

When subscribing to newsletter, if email already exists, don't throw exception, but just warn without exception #19404

Closed
@woutersamaey

Description

@woutersamaey

I want to replace the line in vendor/magento/module-newsletter/Controller/Subscriber/NewAction.php

throw new \Magento\Framework\Exception\LocalizedException(
     __('This email address is already subscribed.')
);

With:

$this->messageManager->addErrorMessage(__('This email address is already subscribed.'));

Reason is: By throwing an exception, it is later caught, added as error message + logged. Since this is a user error, it should not be logged. Our log files don't need these kinds of messages.

Changing this 1 line solves that and only that.

So, before I make a PR and get into a discussion about this. Is it something you would agree to?

Preconditions (*)

Latest Magento version

Steps to reproduce (*)

Try to subscribe an email that is already subscribed. The error log receives a message, but in my view the error log should not get this.

Expected result (*)

Show error, but don't log, it's a user issue, not a platform issue.

Actual result (*)

Error message is shown (good) + message added to log (not desired)

I am willing to make a PR, but only if this reasoning is accepted / agreed on.

Metadata

Metadata

Labels

Component: NewsletterFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions