Use correct exception type when saving segment to DB fails

[MAILPOET-4294]
This commit is contained in:
Rostislav Wolny
2022-08-04 08:56:52 +02:00
committed by Veljko V
parent 1d4ec47b25
commit c8278dde2a

View File

@@ -41,7 +41,15 @@ class Segments {
);
}
$segment = $this->segmentsRepository->createOrUpdate($data['name'], $data['description'] ?? '');
try {
$segment = $this->segmentsRepository->createOrUpdate($data['name'], $data['description'] ?? '');
} catch (\Exception $e) {
throw new APIException(
sprintf(__('Failed to add subscriber: %s', 'mailpoet'), $e->getMessage()),
APIException::FAILED_TO_SAVE_LIST
);
}
return $this->buildItem($segment);
}