diff --git a/src/components/SubscriptionsList.vue b/src/components/SubscriptionsList.vue index 407db418d..fc05d1be5 100644 --- a/src/components/SubscriptionsList.vue +++ b/src/components/SubscriptionsList.vue @@ -102,14 +102,9 @@ import { updateConnection } from '@/api/connection' import { defineColors, getRandomColor } from '@/utils/colors' import LeftPanel from '@/components/LeftPanel.vue' import MyDialog from '@/components/MyDialog.vue' -import { ConnectionModel } from '../views/connections/types' +import { ConnectionModel, SubscribeErrorReason } from '../views/connections/types' import VueI18n from 'vue-i18n' -enum subscribeErrorReason { - normal = 0, - qosSubFailed = 1 << 0, // qos is abnormal - qosSubSysFailed = 1 << 1, // qos is abnormal becauseof $SYS subscribe - emptySubFailed = 1 << 2, // subscription returns empty array -} + @Component({ components: { LeftPanel, @@ -208,24 +203,24 @@ export default class SubscriptionsList extends Vue { /** * Get the error reason message corresponding to the enumeration. - * Check that errorReason not equal `subscribeErrorReason.normal` before using. + * Check that errorReason not equal `SubscribeErrorReason.normal` before using. * @return Return the message of failure subscribe * @param errorReason - Type:enum, The reason cause the failed subscription */ - private getErrorReasonMsg(errorReason: subscribeErrorReason): VueI18n.TranslateResult { - if (errorReason === subscribeErrorReason.normal) return '' + private getErrorReasonMsg(errorReason: SubscribeErrorReason): VueI18n.TranslateResult { + if (errorReason === SubscribeErrorReason.normal) return '' switch (errorReason) { - case errorReason & subscribeErrorReason.qosSubFailed: { + case errorReason & SubscribeErrorReason.qosSubFailed: { return this.$t('connections.qosSubFailed') } - case errorReason & subscribeErrorReason.qosSubSysFailed: { + case errorReason & SubscribeErrorReason.qosSubSysFailed: { return this.$t('connections.qosSubSysFailed') } - case errorReason & subscribeErrorReason.emptySubFailed: { + case errorReason & SubscribeErrorReason.emptySubFailed: { return this.$t('connections.emptySubFailed') } } - return 'Unknow Failed' + return this.$t('connections.unknowSubFailed') } public subscribe({ topic, qos }: SubscriptionModel, isAuto?: boolean) { @@ -240,18 +235,16 @@ export default class SubscriptionsList extends Vue { return false } - let errorReason: subscribeErrorReason = subscribeErrorReason.normal + let errorReason: SubscribeErrorReason = SubscribeErrorReason.normal if (res.length < 1) { - errorReason += subscribeErrorReason.emptySubFailed - } - if (![0, 1, 2].includes(res[0].qos) && topic.match('/^($SYS)//i')?.length) { - errorReason += subscribeErrorReason.qosSubSysFailed - } - if (![0, 1, 2].includes(res[0].qos)) { - errorReason += subscribeErrorReason.qosSubFailed + errorReason = SubscribeErrorReason.emptySubFailed + } else if (![0, 1, 2].includes(res[0].qos) && !topic.match('/^($SYS)//i')) { + errorReason = SubscribeErrorReason.qosSubSysFailed + } else if (![0, 1, 2].includes(res[0].qos)) { + errorReason = SubscribeErrorReason.qosSubFailed } - if (errorReason !== subscribeErrorReason.normal) { + if (errorReason !== SubscribeErrorReason.normal) { const errorReasonMsg: VueI18n.TranslateResult = this.getErrorReasonMsg(errorReason) const errorMsg: string = `${topic} ${this.$t('connections.subFailed')} ${errorReasonMsg}` this.$message.error(errorMsg) diff --git a/src/lang/connections.ts b/src/lang/connections.ts index ae44cbcae..28b97952a 100644 --- a/src/lang/connections.ts +++ b/src/lang/connections.ts @@ -85,20 +85,26 @@ export default { ja: 'サブスクリプションが失敗しました', }, qosSubSysFailed: { - zh: '错误的 QOS,MQTT Broker 拒绝了订阅。请检查 ACL 配置', - en: 'Unexpected QOS, MQTT Broker declined the subscription. Please check ACL configuration', - ja: '予期しないQOS、MQTT Brokerはサブスクリプションを拒否しました。ACL構成を確認してください', + zh: '拒绝了$SYS主题,错误的 QoS,MQTT Broker 拒绝了订阅。请检查 ACL 配置', + en: 'Rejected the $SYS topic,Unexpected QoS, MQTT Broker declined the subscription. Please check ACL configuration', + ja: + '$SYSトピックを拒否しま。した予期しないQoS、MQTT Brokerはサブスクリプションを拒否しました。ACL構成を確認してください', }, qosSubFailed: { - zh: '错误的 QOS', - en: 'Unexpected QOS', - ja: '予期しないQOS', + zh: '错误的 QoS', + en: 'Unexpected QoS', + ja: '予期しないQoS', }, emptySubFailed: { zh: '订阅为空', en: 'Subscription is empty', ja: 'サブスクリプションは空です', }, + unknowSubFailed: { + zh: '未知的订阅错误', + en: 'Unknown subscription error', + ja: '不明なサブスクリプションエラー', + }, connected: { zh: '已连接', en: 'Connected', diff --git a/src/views/connections/types.ts b/src/views/connections/types.ts index 8fc4e4b38..dad1de317 100644 --- a/src/views/connections/types.ts +++ b/src/views/connections/types.ts @@ -105,3 +105,10 @@ export interface ChartDataModel { recevied: number sent: number } + +export enum SubscribeErrorReason { + normal, + qosSubFailed, // qos is abnormal + qosSubSysFailed, // qos is abnormal becauseof $SYS subscribe + emptySubFailed, // subscription returns empty array +}