|
17 | 17 | use Magento\Framework\EntityManager\HydratorInterface;
|
18 | 18 | use Magento\Framework\Exception\CouldNotDeleteException;
|
19 | 19 | use Magento\Framework\Exception\CouldNotSaveException;
|
| 20 | +use Magento\Framework\Exception\LocalizedException; |
20 | 21 | use Magento\Framework\Exception\NoSuchEntityException;
|
21 | 22 | use Magento\Framework\Reflection\DataObjectProcessor;
|
22 | 23 | use Magento\Store\Model\StoreManagerInterface;
|
@@ -162,24 +163,28 @@ private function validateLayoutUpdate(Data\PageInterface $page): void
|
162 | 163 | */
|
163 | 164 | public function save(\Magento\Cms\Api\Data\PageInterface $page)
|
164 | 165 | {
|
165 |
| - if ($page->getStoreId() === null) { |
166 |
| - $storeId = $this->storeManager->getStore()->getId(); |
167 |
| - $page->setStoreId($storeId); |
168 |
| - } |
169 |
| - $pageId = $page->getId(); |
170 |
| - if ($pageId && !($page instanceof Page && $page->getOrigData())) { |
171 |
| - $page = $this->hydrator->hydrate($this->getById($pageId), $this->hydrator->extract($page)); |
172 |
| - } |
173 |
| - |
174 | 166 | try {
|
| 167 | + $pageId = $page->getId(); |
| 168 | + if ($pageId && !($page instanceof Page && $page->getOrigData())) { |
| 169 | + $page = $this->hydrator->hydrate($this->getById($pageId), $this->hydrator->extract($page)); |
| 170 | + } |
| 171 | + if ($page->getStoreId() === null) { |
| 172 | + $storeId = $this->storeManager->getStore()->getId(); |
| 173 | + $page->setStoreId($storeId); |
| 174 | + } |
175 | 175 | $this->validateLayoutUpdate($page);
|
176 | 176 | $this->resource->save($page);
|
177 | 177 | $this->identityMap->add($page);
|
178 |
| - } catch (\Exception $exception) { |
| 178 | + } catch (LocalizedException $exception) { |
179 | 179 | throw new CouldNotSaveException(
|
180 | 180 | __('Could not save the page: %1', $exception->getMessage()),
|
181 | 181 | $exception
|
182 | 182 | );
|
| 183 | + } catch (\Throwable $exception) { |
| 184 | + throw new CouldNotSaveException( |
| 185 | + __('Could not save the page: %1', __('Something went wrong while saving the page.')), |
| 186 | + $exception |
| 187 | + ); |
183 | 188 | }
|
184 | 189 | return $page;
|
185 | 190 | }
|
|
0 commit comments