Skip to content

Commit 87b3b7e

Browse files
author
Viktor Sevch
committed
MC-39338: Improve image upload
1 parent ba65daf commit 87b3b7e

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public function execute()
108108

109109
$result['url'] = $this->productMediaConfig->getTmpMediaUrl($result['file']);
110110
$result['file'] = $result['file'] . '.tmp';
111-
} catch (\Exception $e) {
111+
} catch (LocalizedException $e) {
112112
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
113+
} catch (\Throwable $e) {
114+
$result = ['error' => 'Something went wrong while saving the file(s).', 'errorcode' => 0];
113115
}
114116

115117
/** @var \Magento\Framework\Controller\Result\Raw $response */

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Gallery/UploadTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,31 @@ public function uploadActionWithErrorsDataProvider(): array
198198
'current_path' => '/../../../../_files',
199199
],
200200
'expectation' => [
201-
'message' => 'Wrong file size.',
201+
'message' => 'Something went wrong while saving the file(s).',
202202
'errorcode' => 0,
203203
'tmp_media_path' => '/m/a/magento_empty.jpg',
204204
],
205205
],
206206
'upload_without_image' => [
207207
'file' => [],
208208
'expectation' => [
209-
'message' => '$_FILES array is empty',
209+
'message' => 'Something went wrong while saving the file(s).',
210210
'errorcode' => 0,
211211
],
212212
],
213+
'upload_wrong_png' => [
214+
'file' => [
215+
'copy_file' => true,
216+
'name' => 'magento_wrong.png',
217+
'type' => 'image/png',
218+
'current_path' => '/../../../../_files',
219+
],
220+
'expectation' => [
221+
'message' => 'Something went wrong while saving the file(s).',
222+
'errorcode' => 0,
223+
'tmp_media_path' => '/m/w/magento_wrong.png',
224+
],
225+
]
213226
];
214227
}
215228

Loading

0 commit comments

Comments
 (0)