Skip to content

Improvement: Allow custom error message when logging in #3024

@hiephm

Description

@hiephm

Although Magento 2 allows hooking to event when logging in to add additional validations (just like Magento 1), there is no way to change the error message if those validation failed (e.g by throwing Exception) since a default message is used for general Exception:

# \Magento\Customer\Controller\Account\LoginPost::execute()
                ...
                } catch (\Exception $e) {
                    $this->messageManager->addError(__('Invalid login or password.'));
                }

In the other hand, the same logic in Magento 1 is more customizable:

# \Mage_Customer_AccountController::loginPostAction()
                    switch ($e->getCode()) {
                        ...
                        default:
                            $message = $e->getMessage();
                    }
                    $session->addError($message);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions