From 0eaa1b3feb0f3c584551242739f2f10e8bb623ba Mon Sep 17 00:00:00 2001 From: Mateusz Szczygiel Date: Wed, 13 Sep 2023 11:44:47 +0200 Subject: [PATCH] Better error messages --- .../use-constraints/useConstraints.ts | 28 ++++++++++----- .../use-consumer-groups/useConsumerGroups.ts | 7 ++-- .../groups/use-groups/useGroups.ts | 14 +++++--- .../useInconsistentTopics.ts | 7 ++-- .../readiness/use-readiness/useReadiness.ts | 7 ++-- .../useCreateSubscription.ts | 6 ++-- .../useEditSubscription.ts | 6 ++-- .../use-subscription/useSubscription.ts | 35 +++++++++++++------ .../useOfflineRetransmission.ts | 7 ++-- .../composables/topic/use-topic/useTopic.ts | 7 ++-- 10 files changed, 86 insertions(+), 38 deletions(-) diff --git a/hermes-console-vue/src/composables/constraints/use-constraints/useConstraints.ts b/hermes-console-vue/src/composables/constraints/use-constraints/useConstraints.ts index 724d186700..1861e3a00a 100644 --- a/hermes-console-vue/src/composables/constraints/use-constraints/useConstraints.ts +++ b/hermes-console-vue/src/composables/constraints/use-constraints/useConstraints.ts @@ -68,7 +68,10 @@ export function useConstraints(): UseConstraints { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; await notificationsStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.constraints.topic.created.failure', @@ -76,7 +79,7 @@ export function useConstraints(): UseConstraints { topicName, }, ), - text: (e as Error).message, + text, type: 'error', }); return false; @@ -100,7 +103,10 @@ export function useConstraints(): UseConstraints { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; await notificationsStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.constraints.topic.deleted.failure', @@ -108,7 +114,7 @@ export function useConstraints(): UseConstraints { topicName, }, ), - text: (e as Error).message, + text, type: 'error', }); } @@ -135,7 +141,10 @@ export function useConstraints(): UseConstraints { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; await notificationsStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.constraints.subscription.created.failure', @@ -143,7 +152,7 @@ export function useConstraints(): UseConstraints { subscriptionFqn, }, ), - text: (e as Error).message, + text, type: 'error', }); return false; @@ -171,7 +180,10 @@ export function useConstraints(): UseConstraints { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; await notificationsStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.constraints.subscription.deleted.failure', @@ -179,7 +191,7 @@ export function useConstraints(): UseConstraints { subscriptionFqn, }, ), - text: (e as Error).message, + text, type: 'error', }); return false; diff --git a/hermes-console-vue/src/composables/consumer-groups/use-consumer-groups/useConsumerGroups.ts b/hermes-console-vue/src/composables/consumer-groups/use-consumer-groups/useConsumerGroups.ts index 7ec1af6c23..c087e4d8f5 100644 --- a/hermes-console-vue/src/composables/consumer-groups/use-consumer-groups/useConsumerGroups.ts +++ b/hermes-console-vue/src/composables/consumer-groups/use-consumer-groups/useConsumerGroups.ts @@ -56,7 +56,10 @@ export function useConsumerGroups( text: '', type: 'success', }); - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; await notificationsStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.subscriptionOffsets.move.failure', @@ -64,7 +67,7 @@ export function useConsumerGroups( subscriptionName, }, ), - text: (e as Error).message, + text, type: 'error', }); } diff --git a/hermes-console-vue/src/composables/groups/use-groups/useGroups.ts b/hermes-console-vue/src/composables/groups/use-groups/useGroups.ts index c6c2e9793f..9e7468db86 100644 --- a/hermes-console-vue/src/composables/groups/use-groups/useGroups.ts +++ b/hermes-console-vue/src/composables/groups/use-groups/useGroups.ts @@ -84,12 +84,15 @@ export function useGroups(): UseGroups { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t('notifications.group.delete.failure', { groupId, }), - text: (e as Error).message, + text, type: 'error', }); return false; @@ -107,12 +110,15 @@ export function useGroups(): UseGroups { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t('notifications.group.create.failure', { groupId, }), - text: (e as Error).message, + text, type: 'error', }); return false; diff --git a/hermes-console-vue/src/composables/inconsistent-topics/use-inconsistent-topics/useInconsistentTopics.ts b/hermes-console-vue/src/composables/inconsistent-topics/use-inconsistent-topics/useInconsistentTopics.ts index a2e104d40d..dbf54fa59b 100644 --- a/hermes-console-vue/src/composables/inconsistent-topics/use-inconsistent-topics/useInconsistentTopics.ts +++ b/hermes-console-vue/src/composables/inconsistent-topics/use-inconsistent-topics/useInconsistentTopics.ts @@ -55,7 +55,10 @@ export function useInconsistentTopics(): UseInconsistentTopics { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.inconsistentTopic.delete.failure', @@ -63,7 +66,7 @@ export function useInconsistentTopics(): UseInconsistentTopics { topic, }, ), - text: (e as Error).message, + text, type: 'error', }); return false; diff --git a/hermes-console-vue/src/composables/readiness/use-readiness/useReadiness.ts b/hermes-console-vue/src/composables/readiness/use-readiness/useReadiness.ts index 0df0d56b67..5c7f81ead5 100644 --- a/hermes-console-vue/src/composables/readiness/use-readiness/useReadiness.ts +++ b/hermes-console-vue/src/composables/readiness/use-readiness/useReadiness.ts @@ -55,12 +55,15 @@ export function useReadiness(): UseReadiness { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t('notifications.readiness.switch.failure', { datacenter, }), - text: (e as Error).message, + text, type: 'error', }); return false; diff --git a/hermes-console-vue/src/composables/subscription/use-create-subscription/useCreateSubscription.ts b/hermes-console-vue/src/composables/subscription/use-create-subscription/useCreateSubscription.ts index 21d1cd7284..a7337b92f9 100644 --- a/hermes-console-vue/src/composables/subscription/use-create-subscription/useCreateSubscription.ts +++ b/hermes-console-vue/src/composables/subscription/use-create-subscription/useCreateSubscription.ts @@ -1,4 +1,3 @@ -import { AxiosError } from 'axios'; import { createSubscription as doCreateSubscription, searchOwners, @@ -90,8 +89,9 @@ export function useCreateSubscription(topic: string): UseCreateSubscription { }); return true; } catch (e: any) { - const text = - e instanceof AxiosError ? e.message : 'Unknown error occurred'; + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationsStore.dispatchNotification({ title: useGlobalI18n().t('notifications.subscription.create.failure'), text, diff --git a/hermes-console-vue/src/composables/subscription/use-edit-subscription/useEditSubscription.ts b/hermes-console-vue/src/composables/subscription/use-edit-subscription/useEditSubscription.ts index d306304cd4..9b57fae207 100644 --- a/hermes-console-vue/src/composables/subscription/use-edit-subscription/useEditSubscription.ts +++ b/hermes-console-vue/src/composables/subscription/use-edit-subscription/useEditSubscription.ts @@ -1,4 +1,3 @@ -import { AxiosError } from 'axios'; import { editSubscription as doEditSubscription, fetchOwner, @@ -96,8 +95,9 @@ export function useEditSubscription( }); return true; } catch (e: any) { - const text = - e instanceof AxiosError ? e.message : 'Unknown error occurred'; + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationsStore.dispatchNotification({ title: useGlobalI18n().t('notifications.subscription.edit.failure'), text, diff --git a/hermes-console-vue/src/composables/subscription/use-subscription/useSubscription.ts b/hermes-console-vue/src/composables/subscription/use-subscription/useSubscription.ts index 0d6072c7ba..a964ea95a9 100644 --- a/hermes-console-vue/src/composables/subscription/use-subscription/useSubscription.ts +++ b/hermes-console-vue/src/composables/subscription/use-subscription/useSubscription.ts @@ -153,12 +153,15 @@ export function useSubscription( type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t('notifications.subscription.delete.failure', { subscriptionName, }), - text: (e as Error).message, + text, type: 'error', }); return false; @@ -175,12 +178,15 @@ export function useSubscription( type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t('notifications.subscription.suspend.failure', { subscriptionName, }), - text: (e as Error).message, + text, type: 'error', }); return false; @@ -197,7 +203,10 @@ export function useSubscription( type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.subscription.activate.failure', @@ -205,7 +214,7 @@ export function useSubscription( subscriptionName, }, ), - text: (e as Error).message, + text, type: 'error', }); return false; @@ -228,7 +237,10 @@ export function useSubscription( type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.subscription.retransmit.failure', @@ -236,7 +248,7 @@ export function useSubscription( subscriptionName, }, ), - text: (e as Error).message, + text, type: 'error', }); return false; @@ -261,7 +273,10 @@ export function useSubscription( type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.subscription.skipAllMessages.failure', @@ -269,7 +284,7 @@ export function useSubscription( subscriptionName, }, ), - text: (e as Error).message, + text, type: 'error', }); return false; diff --git a/hermes-console-vue/src/composables/topic/use-offline-retransmission/useOfflineRetransmission.ts b/hermes-console-vue/src/composables/topic/use-offline-retransmission/useOfflineRetransmission.ts index da8d92abcb..5ba618b873 100644 --- a/hermes-console-vue/src/composables/topic/use-offline-retransmission/useOfflineRetransmission.ts +++ b/hermes-console-vue/src/composables/topic/use-offline-retransmission/useOfflineRetransmission.ts @@ -23,13 +23,16 @@ export function useOfflineRetransmission(): UseOfflineRetransmission { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; await notificationsStore.dispatchNotification({ title: useGlobalI18n().t( 'notifications.offlineRetransmission.create.failure', { sourceTopic: task.sourceTopic, targetTopic: task.targetTopic }, ), - text: (e as Error).message, + text, type: 'error', }); return false; diff --git a/hermes-console-vue/src/composables/topic/use-topic/useTopic.ts b/hermes-console-vue/src/composables/topic/use-topic/useTopic.ts index 4cf78c161d..853a6a0d65 100644 --- a/hermes-console-vue/src/composables/topic/use-topic/useTopic.ts +++ b/hermes-console-vue/src/composables/topic/use-topic/useTopic.ts @@ -157,12 +157,15 @@ export function useTopic(topicName: string): UseTopic { type: 'success', }); return true; - } catch (e) { + } catch (e: any) { + const text = e.response?.data?.message + ? e.response.data.message + : 'Unknown error occurred'; notificationStore.dispatchNotification({ title: useGlobalI18n().t('notifications.topic.delete.failure', { topicName, }), - text: (e as Error).message, + text, type: 'error', }); return false;