From 0ce641d10b9f044f7b1642e80801040e4501c0c9 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 15 Sep 2022 12:45:16 +0100 Subject: [PATCH] [WIFI-10850] Error descriptions on command failures Signed-off-by: Charles --- package-lock.json | 4 +-- package.json | 2 +- public/locales/de/translation.json | 1 + public/locales/en/translation.json | 1 + public/locales/es/translation.json | 1 + public/locales/fr/translation.json | 1 + public/locales/pt/translation.json | 1 + src/components/BlinkModal/index.js | 13 +++++++- src/components/ConfigureModal/index.js | 17 ++++++---- src/components/DeviceActionCard/index.js | 37 ++++++++++++--------- src/components/DeviceFirmwareModal/index.js | 13 +++++++- src/components/EventQueueModal/index.js | 17 ++++++---- src/components/FactoryResetModal/index.js | 16 +++++++-- src/components/RebootModal/index.js | 13 +++++++- src/components/TelemetryModal/index.js | 17 ++++++---- src/components/TraceModal/index.js | 16 +++++++-- src/components/WifiScanModal/index.js | 16 +++++++-- 17 files changed, 141 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1912493..256a5da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ucentral-client", - "version": "2.7.0(5)", + "version": "2.7.0(6)", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ucentral-client", - "version": "2.7.0(5)", + "version": "2.7.0(6)", "dependencies": { "@coreui/coreui": "^3.4.0", "@coreui/icons": "^2.0.1", diff --git a/package.json b/package.json index cd795f1..3062dc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ucentral-client", - "version": "2.7.0(5)", + "version": "2.7.0(6)", "dependencies": { "@coreui/coreui": "^3.4.0", "@coreui/icons": "^2.0.1", diff --git a/public/locales/de/translation.json b/public/locales/de/translation.json index b3c3b4c..54279b3 100644 --- a/public/locales/de/translation.json +++ b/public/locales/de/translation.json @@ -326,6 +326,7 @@ "device": { "add_to_blacklist": "Gerät zur Blacklist hinzufügen", "all_devices": "Alle Geräte", + "already_running_command": "Gerät führt bereits einen Befehl aus, bitte versuchen Sie es später erneut", "blacklisted_on": "Datum", "capabilities": "Fähigkeiten", "certificate_explanation": "Zertifikate der angeschlossenen Geräte", diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index c87971a..9f3fe06 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -326,6 +326,7 @@ "device": { "add_to_blacklist": "Add Device To Blacklist", "all_devices": "All Devices", + "already_running_command": "Device is already executing a command, please try later", "blacklisted_on": "Date", "capabilities": "Capabilities", "certificate_explanation": "Certificates of connected devices", diff --git a/public/locales/es/translation.json b/public/locales/es/translation.json index c6d3568..d44b526 100644 --- a/public/locales/es/translation.json +++ b/public/locales/es/translation.json @@ -326,6 +326,7 @@ "device": { "add_to_blacklist": "Agregar dispositivo a la lista negra", "all_devices": "Todos los dispositivos", + "already_running_command": "El dispositivo ya está ejecutando un comando, intente más tarde", "blacklisted_on": "Fecha", "capabilities": "capacidades", "certificate_explanation": "Certificados de dispositivos conectados", diff --git a/public/locales/fr/translation.json b/public/locales/fr/translation.json index 11e0fc7..3853fce 100644 --- a/public/locales/fr/translation.json +++ b/public/locales/fr/translation.json @@ -326,6 +326,7 @@ "device": { "add_to_blacklist": "Ajouter un appareil à la liste noire", "all_devices": "Tous les dispositifs", + "already_running_command": "L'appareil exécute déjà une commande, veuillez réessayer plus tard", "blacklisted_on": "Rendez-vous amoureux", "capabilities": "Capacités", "certificate_explanation": "Certificats des appareils connectés", diff --git a/public/locales/pt/translation.json b/public/locales/pt/translation.json index bfa8b8b..6fd25a0 100644 --- a/public/locales/pt/translation.json +++ b/public/locales/pt/translation.json @@ -326,6 +326,7 @@ "device": { "add_to_blacklist": "Adicionar dispositivo à lista negra", "all_devices": "Todos os dispositivos", + "already_running_command": "O dispositivo já está executando um comando, tente mais tarde", "blacklisted_on": "Encontro", "capabilities": "Recursos", "certificate_explanation": "Certificados de dispositivos conectados", diff --git a/src/components/BlinkModal/index.js b/src/components/BlinkModal/index.js index 2bad02a..4edec06 100644 --- a/src/components/BlinkModal/index.js +++ b/src/components/BlinkModal/index.js @@ -72,7 +72,18 @@ const BlinkModal = ({ show, toggleModal }) => { } toggleModal(); }) - .catch(() => { + .catch((e) => { + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } setResult('error'); }) .finally(() => { diff --git a/src/components/ConfigureModal/index.js b/src/components/ConfigureModal/index.js index 5375714..373b2bc 100644 --- a/src/components/ConfigureModal/index.js +++ b/src/components/ConfigureModal/index.js @@ -103,12 +103,17 @@ const ConfigureModal = ({ show, toggleModal }) => { }) .catch((e) => { setResponseBody('Error while submitting command!'); - addToast({ - title: t('common.error'), - body: `${t('common.general_error')}: ${e.response?.data?.ErrorDescription}`, - color: 'danger', - autohide: true, - }); + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } setHadFailure(true); }) .finally(() => { diff --git a/src/components/DeviceActionCard/index.js b/src/components/DeviceActionCard/index.js index b86ee0b..b1c1943 100644 --- a/src/components/DeviceActionCard/index.js +++ b/src/components/DeviceActionCard/index.js @@ -54,12 +54,17 @@ const DeviceActions = ({ device }) => { if (newWindow) newWindow.opener = null; }) .catch((e) => { - addToast({ - title: t('common.error'), - body: t('connect.error_trying_to_connect', { error: e.response?.data?.ErrorDescription }), - color: 'danger', - autohide: true, - }); + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } }) .finally(() => { setConnectLoading(false); @@ -68,18 +73,20 @@ const DeviceActions = ({ device }) => { useEffect(() => { if (upgradeStatus.result !== undefined) { - addToast({ - title: upgradeStatus.result.success ? t('common.success') : t('common.error'), - body: upgradeStatus.result.success - ? t('firmware.upgrade_command_submitted') - : upgradeStatus.result.error, - color: upgradeStatus.result.success ? 'success' : 'danger', - autohide: true, - }); + if (upgradeStatus.result.success) { + addToast({ + title: upgradeStatus.result.success ? t('common.success') : t('common.error'), + body: upgradeStatus.result.success + ? t('firmware.upgrade_command_submitted') + : upgradeStatus.result.error, + color: upgradeStatus.result.success ? 'success' : 'danger', + autohide: true, + }); + setShowUpgradeModal(false); + } setUpgradeStatus({ loading: false, }); - setShowUpgradeModal(false); } }, [upgradeStatus]); diff --git a/src/components/DeviceFirmwareModal/index.js b/src/components/DeviceFirmwareModal/index.js index 5957f6d..6fe4caf 100644 --- a/src/components/DeviceFirmwareModal/index.js +++ b/src/components/DeviceFirmwareModal/index.js @@ -111,7 +111,18 @@ const DeviceFirmwareModal = ({ }, }); }) - .catch(() => { + .catch((e) => { + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } setUpgradeStatus({ loading: false, result: { diff --git a/src/components/EventQueueModal/index.js b/src/components/EventQueueModal/index.js index c6642f9..a8fe4a8 100644 --- a/src/components/EventQueueModal/index.js +++ b/src/components/EventQueueModal/index.js @@ -34,12 +34,17 @@ const EventQueueModal = ({ show, toggle }) => { setResult(response.data); }) .catch((e) => { - addToast({ - title: t('common.error'), - body: t('commands.unable_queue', { error: e.response?.data?.ErrorDescription }), - color: 'danger', - autohide: true, - }); + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } }) .finally(() => { setLoading(false); diff --git a/src/components/FactoryResetModal/index.js b/src/components/FactoryResetModal/index.js index 99e4091..25eb498 100644 --- a/src/components/FactoryResetModal/index.js +++ b/src/components/FactoryResetModal/index.js @@ -18,7 +18,7 @@ import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import PropTypes from 'prop-types'; import 'react-widgets/styles.css'; -import { useAuth, useDevice } from 'ucentral-libs'; +import { useAuth, useDevice, useToast } from 'ucentral-libs'; import axiosInstance from 'utils/axiosInstance'; import SuccessfulActionModalBody from 'components/SuccessfulActionModalBody'; @@ -26,6 +26,7 @@ const ConfigureModal = ({ show, toggleModal }) => { const { t } = useTranslation(); const { currentToken, endpoints } = useAuth(); const { deviceSerialNumber } = useDevice(); + const { addToast } = useToast(); const [hadSuccess, setHadSuccess] = useState(false); const [hadFailure, setHadFailure] = useState(false); const [doingNow, setDoingNow] = useState(false); @@ -74,7 +75,18 @@ const ConfigureModal = ({ show, toggleModal }) => { .then(() => { setHadSuccess(true); }) - .catch(() => { + .catch((e) => { + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } setResponseBody(t('commands.error')); setHadFailure(true); }) diff --git a/src/components/RebootModal/index.js b/src/components/RebootModal/index.js index c8b09cb..ecbe9ec 100644 --- a/src/components/RebootModal/index.js +++ b/src/components/RebootModal/index.js @@ -89,7 +89,18 @@ const ActionModal = ({ show, toggleModal }) => { }); toggleModal(); }) - .catch(() => { + .catch((e) => { + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } setResult('error'); }) .finally(() => { diff --git a/src/components/TelemetryModal/index.js b/src/components/TelemetryModal/index.js index f95fe64..09f7ad2 100644 --- a/src/components/TelemetryModal/index.js +++ b/src/components/TelemetryModal/index.js @@ -105,12 +105,17 @@ const TelemetryModal = ({ show, toggle }) => { } }) .catch((e) => { - addToast({ - title: t('common.error'), - body: t('telemetry.connection_failed', { error: e.response?.data?.ErrorDescription }), - color: 'danger', - autohide: true, - }); + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } }) .finally(() => setLoading(false)); }; diff --git a/src/components/TraceModal/index.js b/src/components/TraceModal/index.js index 2e54b0f..81a0671 100644 --- a/src/components/TraceModal/index.js +++ b/src/components/TraceModal/index.js @@ -23,13 +23,14 @@ import PropTypes from 'prop-types'; import 'react-widgets/styles.css'; import axiosInstance from 'utils/axiosInstance'; import eventBus from 'utils/eventBus'; -import { LoadingButton, useAuth, useDevice } from 'ucentral-libs'; +import { LoadingButton, useAuth, useDevice, useToast } from 'ucentral-libs'; import SuccessfulActionModalBody from 'components/SuccessfulActionModalBody'; import WaitingForTraceBody from './WaitingForTraceBody'; const TraceModal = ({ show, toggleModal }) => { const { t } = useTranslation(); const { currentToken, endpoints } = useAuth(); + const { addToast } = useToast(); const { deviceSerialNumber, getDeviceConnection } = useDevice(); const [hadSuccess, setHadSuccess] = useState(false); const [hadFailure, setHadFailure] = useState(false); @@ -94,7 +95,18 @@ const TraceModal = ({ show, toggleModal }) => { setWaitingForTrace(true); } }) - .catch(() => { + .catch((e) => { + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } setResponseBody(t('commands.error')); setHadFailure(true); }) diff --git a/src/components/WifiScanModal/index.js b/src/components/WifiScanModal/index.js index 4370d72..5ecc158 100644 --- a/src/components/WifiScanModal/index.js +++ b/src/components/WifiScanModal/index.js @@ -20,7 +20,7 @@ import PropTypes from 'prop-types'; import axiosInstance from 'utils/axiosInstance'; import eventBus from 'utils/eventBus'; import { prettyDateForFile } from 'utils/helper'; -import { useAuth, useDevice } from 'ucentral-libs'; +import { useAuth, useDevice, useToast } from 'ucentral-libs'; import WifiChannelTable from 'components/WifiScanResultModal/WifiChannelTable'; import 'react-widgets/styles.css'; import { CSVLink } from 'react-csv'; @@ -33,6 +33,7 @@ const WifiScanModal = ({ show, toggleModal }) => { const { t } = useTranslation(); const { currentToken, endpoints } = useAuth(); const { deviceSerialNumber } = useDevice(); + const { addToast } = useToast(); const [hadSuccess, setHadSuccess] = useState(false); const [selectedIes, setSelectedIes] = useState(undefined); const [hadFailure, setHadFailure] = useState(false); @@ -172,7 +173,18 @@ const WifiScanModal = ({ show, toggleModal }) => { setHadFailure(true); } }) - .catch(() => { + .catch((e) => { + if (e.response?.data?.ErrorDescription !== undefined) { + const split = e.response?.data?.ErrorDescription.split(':'); + if (split !== undefined && split.length >= 2) { + addToast({ + title: t('common.error'), + body: split[1], + color: 'danger', + autohide: true, + }); + } + } setHadFailure(true); }) .finally(() => {