Skip to content

Commit 94ef051

Browse files
committed
Refactoring to catch NoSUchEntoty Exception
1 parent f5cb772 commit 94ef051

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

AdobeStockImageAdminUi/Controller/Adminhtml/Asset/GetMediaGalleryAsset.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Controller\ResultFactory;
1414
use Psr\Log\LoggerInterface;
1515
use Magento\AdobeStockImageAdminUi\Model\Asset\GetMediaGalleryAssetByAdobeId;
16+
use Magento\Framework\Exception\NoSuchEntityException;
1617

1718
/**
1819
* Backend controller for retrieving asset information by adobeId
@@ -61,7 +62,6 @@ public function execute()
6162
{
6263
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
6364
try {
64-
6565
$params = $this->getRequest()->getParams();
6666
$adobeId = isset($params['adobe_id']) ? $params['adobe_id'] : null;
6767

@@ -78,6 +78,9 @@ public function execute()
7878

7979
$responseCode = self::HTTP_OK;
8080
$responseContent = $this->getAssetByAdobeId->execute((int) $adobeId);
81+
} catch (NoSuchEntityException $execption) {
82+
$responseCode = self::HTTP_OK;
83+
$responseContent = [];
8184
} catch (\Exception $exception) {
8285
$responseCode = self::HTTP_INTERNAL_ERROR;
8386
$this->logger->critical($exception);

AdobeStockImageAdminUi/Model/Asset/GetMediaGalleryAssetByAdobeId.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface;
1313
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
1414
use Magento\Framework\Reflection\DataObjectProcessor;
15+
use Magento\Framework\Exception\NoSuchEntityException;
1516

1617
/**
1718
* Return media gallery asset by adobe id
@@ -55,13 +56,19 @@ public function __construct(
5556
*
5657
* @param int $adobeId
5758
* @return array
59+
* @throws NoSuchEntityException
5860
*/
5961
public function execute(int $adobeId): array
6062
{
6163
$mediaGalleryAsset = $this->getAssetByAdobeId->execute([$adobeId]);
6264

6365
if (!isset($mediaGalleryAsset[$adobeId])) {
64-
return [];
66+
throw new NoSuchEntityException(
67+
__(
68+
'Media Gallery asset with adobe id %id does not exist.',
69+
['id' => $adobeId]
70+
)
71+
);
6572
}
6673

6774
$mediaGalleryId = $mediaGalleryAsset[$adobeId]->getMediaGalleryId();

AdobeStockImageAdminUi/view/adminhtml/web/js/components/grid/column/image-preview.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,12 @@ define([
6161
*/
6262
initialize: function () {
6363
this._super().initView();
64-
$(window).on('fileDeleted.enhancedMediaGallery', function () {
65-
this.reloadAdobeGrid();
66-
}.bind(this));
67-
$(window).on('folderDeleted.enhancedMediaGallery', function () {
68-
this.reloadAdobeGrid();
69-
}.bind(this));
64+
$(window).on('fileDeleted.enhancedMediaGallery', this.reloadAdobeGrid.bind(this));
65+
$(window).on('folderDeleted.enhancedMediaGallery', this.reloadAdobeGrid.bind(this));
7066

7167
return this;
7268
},
7369

74-
/**
75-
* Update is_downloaded filed for displayed record
76-
*/
77-
updateIsDownloadedField: function () {
78-
var record = this.displayedRecord();
79-
80-
this.actions().getAssetDetails(this.displayedRecord().id).then(function (assetDetails) {
81-
if (assetDetails.length === 0) {
82-
record['is_downloaded'] = 0;
83-
this.displayedRecord(record);
84-
}
85-
}.bind(this));
86-
},
87-
8870
/**
8971
* Initialize child components
9072
*
@@ -207,7 +189,6 @@ define([
207189
* Reload Adobe grid after deleting image
208190
*/
209191
reloadAdobeGrid: function () {
210-
this.updateIsDownloadedField();
211192
this.actions().source().reload({
212193
refresh: true
213194
});

0 commit comments

Comments
 (0)