From 2444f4540d185e0a0db8cf97210226ccae42ae6f Mon Sep 17 00:00:00 2001 From: Marco Perberschlager Date: Mon, 21 Oct 2024 12:29:46 +0200 Subject: [PATCH] Fixed error message for import --- src/Controller/ConfigController.php | 30 ++++++++++++++++------------- src/Resources/public/js/config.js | 6 ++++-- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php index 1a5a9d4a..2551d232 100644 --- a/src/Controller/ConfigController.php +++ b/src/Controller/ConfigController.php @@ -576,19 +576,23 @@ public function exportConfiguration(Request $request, ExportService $exportServi */ public function importConfiguration(Request $request, ImportService $importService): JsonResponse { - $this->checkPermission(self::CONFIG_NAME); - $json = file_get_contents($_FILES['Filedata']['tmp_name']); - $configuration = $importService->importConfigurationJson($json); - - $response = $this->jsonResponse([ - 'success' => true, - 'type' => $configuration->getType(), - 'name' => $configuration->getName(), - ]); - // set content-type to text/html, otherwise (when application/json is sent) chrome will complain in - // Ext.form.Action.Submit and mark the submission as failed - $response->headers->set('Content-Type', 'text/html'); + try { + $this->checkPermission(self::CONFIG_NAME); + $json = file_get_contents($_FILES['Filedata']['tmp_name']); + $configuration = $importService->importConfigurationJson($json); - return $response; + $response = $this->jsonResponse([ + 'success' => true, + 'type' => $configuration->getType(), + 'name' => $configuration->getName(), + ]); + // set content-type to text/html, otherwise (when application/json is sent) chrome will complain in + // Ext.form.Action.Submit and mark the submission as failed + $response->headers->set('Content-Type', 'text/html'); + + return $response; + } catch (\Exception $e) { + return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]); + } } } diff --git a/src/Resources/public/js/config.js b/src/Resources/public/js/config.js index ee531d2d..e14bd3e0 100644 --- a/src/Resources/public/js/config.js +++ b/src/Resources/public/js/config.js @@ -124,8 +124,10 @@ pimcore.plugin.datahub.config = Class.create({ this.refreshTree(); }.bind(this), - function () { - Ext.MessageBox.alert(t("error"), t("error")); + function (response) { + response = response.response; + const data = Ext.decode(response.responseText); + Ext.MessageBox.alert(t("error"), data.message); } ); }.bind(this)