From bce6d63c6c270e7c87b9fb9116f5900087729711 Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Wed, 8 Jan 2025 22:13:56 +0100 Subject: [PATCH] feat: show error message from opml import in web-ui Signed-off-by: Wolfgang --- CHANGELOG.md | 1 + lib/Controller/ImportController.php | 20 ++++++++++++++++++-- src/components/Sidebar.vue | 7 ++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 851fd9902..204b01b1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the ## [25.x.x] ### Changed - add explanations for the individual values in the feed information table +- show error message from `opml` import in web-ui ### Fixed diff --git a/lib/Controller/ImportController.php b/lib/Controller/ImportController.php index e94e298ba..9403fd14e 100644 --- a/lib/Controller/ImportController.php +++ b/lib/Controller/ImportController.php @@ -14,6 +14,7 @@ namespace OCA\News\Controller; use OCA\News\Service\OpmlService; +use OCA\News\Service\Exceptions\ServiceValidationException; use \OCP\IRequest; use OCP\IUserSession; use OCP\AppFramework\Http\Attribute\NoAdminRequired; @@ -38,7 +39,7 @@ public function __construct( #[NoCSRFRequired] #[NoAdminRequired] - public function opml(): void + public function opml(): array { $data = ''; if (isset($this->request->files['file'])) { @@ -49,6 +50,21 @@ public function opml(): void } - $this->opmlService->import($this->getUserId(), $data); + $status = ''; + $message = ''; + try { + $this->opmlService->import($this->getUserId(), $data); + $status = "ok"; + } catch (ServiceValidationException $e) { + $status = "error"; + $message = $e->getMessage(); + } + + $response = [ + 'status' => $status, + 'message' => $message, + ]; + + return $response; } } diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 069497280..0ee131d9e 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -540,7 +540,12 @@ export default Vue.extend({ }) if (response.ok) { - showSuccess(t('news', 'File successfully uploaded')) + const data = await response.json() + if (data.status === 'ok') { + showSuccess(t('news', 'File successfully uploaded')) + } else { + showError(data.message, { timeout: -1 }) + } } else { showError(t('news', 'Error uploading the opml file')) }