Skip to content

Commit 6c2a081

Browse files
author
Dmytro Poperechnyy
committed
MAGETWO-33814: Change parent class of Model\Exception sub-classes to Localized
- Added new Magento\Framework\Exception\Customer\Exception; - Eliminated check by error code from AccountManagement class;
1 parent aac255f commit 6c2a081

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Magento\Framework\Exception\EmailNotConfirmedException;
2525
use Magento\Framework\Exception\InputException;
2626
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
27+
use Magento\Framework\Exception\LocalizedException;
2728
use Magento\Framework\Exception\NoSuchEntityException;
2829
use Magento\Framework\Exception\State\ExpiredException;
2930
use Magento\Framework\Exception\State\InputMismatchException;
@@ -511,10 +512,9 @@ public function createAccountWithPasswordHash(
511512
try {
512513
// If customer exists existing hash will be used by Repository
513514
$customer = $this->customerRepository->save($customer, $hash);
514-
} catch (\Magento\Customer\Exception $e) {
515-
if ($e->getCode() === CustomerModel::EXCEPTION_EMAIL_EXISTS) {
516-
throw new InputMismatchException('Customer with the same email already exists in associated website.');
517-
}
515+
} catch (\Magento\Framework\Exception\Customer\Exception $e) {
516+
throw new InputMismatchException('Customer with the same email already exists in associated website.');
517+
} catch (LocalizedException $e) {
518518
throw $e;
519519
}
520520

app/code/Magento/Customer/Model/Resource/Customer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ protected function _getDefaultAttributes()
9292
*
9393
* @param \Magento\Framework\Object $customer
9494
* @return $this
95-
* @throws \Magento\Customer\Exception
95+
* @throws \Magento\Framework\Exception\Customer\Exception
96+
* @throws \Magento\Framework\Validator\ValidatorException
9697
* @throws \Magento\Framework\Model\Exception
9798
*/
9899
protected function _beforeSave(\Magento\Framework\Object $customer)
@@ -101,7 +102,7 @@ protected function _beforeSave(\Magento\Framework\Object $customer)
101102
parent::_beforeSave($customer);
102103

103104
if (!$customer->getEmail()) {
104-
throw new \Magento\Customer\Exception(__('Customer email is required'));
105+
throw new \Magento\Framework\Exception\Customer\Exception(__('Customer email is required'));
105106
}
106107

107108
$adapter = $this->_getWriteAdapter();
@@ -124,9 +125,8 @@ protected function _beforeSave(\Magento\Framework\Object $customer)
124125

125126
$result = $adapter->fetchOne($select, $bind);
126127
if ($result) {
127-
throw new \Magento\Customer\Exception(
128-
__('Customer with the same email already exists in associated website.'),
129-
\Magento\Customer\Model\Customer::EXCEPTION_EMAIL_EXISTS
128+
throw new \Magento\Framework\Exception\Customer\Exception(
129+
__('Customer with the same email already exists in associated website.')
130130
);
131131
}
132132

dev/tests/integration/testsuite/Magento/Tax/Model/TaxClass/RepositoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public function testSave()
6666

6767
/**
6868
* @magentoDbIsolation enabled
69-
* @expectedException \Magento\Framework\Exception\InputException
70-
* @expectedExceptionMessage A class with the same name already exists for ClassType PRODUCT.
69+
* @expectedException \Magento\Framework\Exception\AlreadyExistsException
70+
* @expectedExceptionMessage Class name and class type already exists.
7171
*/
7272
public function testSaveThrowsExceptionIfGivenTaxClassNameIsNotUnique()
7373
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Exception\Customer;
7+
8+
use Magento\Framework\Exception\LocalizedException;
9+
10+
class Exception extends LocalizedException
11+
{
12+
}

0 commit comments

Comments
 (0)