Remove catch block and change quotes
Remove catch block to log unexpected exceptions and change quotes for consistency on error message. [MAILPOET-4259]
This commit is contained in:
@@ -152,6 +152,7 @@ class Subscribers extends APIEndpoint {
|
||||
/**
|
||||
* @param array $data
|
||||
* @return ErrorResponse|SuccessResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function save(array $data = []) {
|
||||
try {
|
||||
@@ -162,11 +163,8 @@ class Subscribers extends APIEndpoint {
|
||||
return $this->badRequest([
|
||||
APIError::BAD_REQUEST => $conflictException->getMessage(),
|
||||
]);
|
||||
} catch (\Exception $unknownException) {
|
||||
return $this->badRequest([
|
||||
APIError::UNKNOWN => __('Saving subscriber failed.', 'mailpoet'),
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
return $this->successResponse(
|
||||
$this->subscribersResponseBuilder->build($subscriber)
|
||||
);
|
||||
|
@@ -229,7 +229,7 @@ class SubscriberSaveController {
|
||||
private function verifyEmailIsUnique(string $email): void {
|
||||
$existingSubscriber = $this->subscribersRepository->findOneBy(['email' => $email]);
|
||||
if ($existingSubscriber) {
|
||||
$exceptionMessage = __(sprintf("A subscriber with E-mail '%s' already exists.", $email), 'mailpoet');
|
||||
$exceptionMessage = __(sprintf('A subscriber with E-mail "%s" already exists.', $email), 'mailpoet');
|
||||
throw new ConflictException($exceptionMessage);
|
||||
}
|
||||
}
|
||||
|
@@ -295,7 +295,7 @@ class SubscribersTest extends \MailPoetTest {
|
||||
$response = $this->endpoint->save($subscriberData);
|
||||
$this->assertInstanceOf(ErrorResponse::class, $response);
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals("A subscriber with E-mail '{$this->subscriber1->getEmail()}' already exists.");
|
||||
expect($response->errors[0]['message'])->equals('A subscriber with E-mail "' . $this->subscriber1->getEmail() . '" already exists.');
|
||||
}
|
||||
|
||||
public function testItCanRemoveListsFromAnExistingSubscriber() {
|
||||
|
@@ -99,7 +99,7 @@ class SubscriberSaveControllerTest extends \MailPoetTest {
|
||||
|
||||
$this->entityManager->clear();
|
||||
$this->expectException(ConflictException::class);
|
||||
$this->expectExceptionMessage("A subscriber with E-mail '{$subscriber2->getEmail()}' already exists.");
|
||||
$this->expectExceptionMessage('A subscriber with E-mail "' . $subscriber2->getEmail() . '" already exists.');
|
||||
|
||||
$this->saveController->save($data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user