cancel
Showing results for 
Search instead for 
Did you mean: 

Improvement: Allow custom error message when logging in

0 Kudos

Improvement: Allow custom error message when logging in

Feature request from hiephm, posted on GitHub Jan 18, 2016

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);