diff --git a/src/components/MsgPublish.vue b/src/components/MsgPublish.vue index 20c5ef049..9f6494eff 100644 --- a/src/components/MsgPublish.vue +++ b/src/components/MsgPublish.vue @@ -506,9 +506,13 @@ export default class MsgPublish extends Vue { } private formatJsonValue() { - const jsonValue = validFormatJson(this.msgRecord.payload.toString()) - if (jsonValue) { - this.msgRecord.payload = jsonValue + try { + let jsonValue: string | undefined = validFormatJson(this.msgRecord.payload.toString()) + if (jsonValue) { + this.msgRecord.payload = jsonValue + } + } catch (error) { + this.$message.error((error as Error).toString()) } } diff --git a/src/utils/validFormatJson.ts b/src/utils/validFormatJson.ts index 800eab67a..07c33937b 100644 --- a/src/utils/validFormatJson.ts +++ b/src/utils/validFormatJson.ts @@ -13,6 +13,6 @@ export default (jsonStrValue: string, warnMessage?: TranslateResult) => { if (warnMessage) { errorMessage = `${warnMessage} ${errorMessage}` } - throw error + throw errorMessage } } diff --git a/src/views/connections/ConnectionsDetail.vue b/src/views/connections/ConnectionsDetail.vue index 51812f66b..48bb43def 100644 --- a/src/views/connections/ConnectionsDetail.vue +++ b/src/views/connections/ConnectionsDetail.vue @@ -1490,7 +1490,6 @@ export default class ConnectionsDetail extends Vue { validFormatJson(publishValue.toString(), this.$t('connections.publishMsg')) } catch (error) { this.$message.error((error as Error).toString()) - return } } return publishValue @@ -1503,7 +1502,12 @@ export default class ConnectionsDetail extends Vue { return receiveValue.toString('hex').replace(/(.{4})/g, '$1 ') } if (receiveType === 'JSON') { - const jsonValue = validFormatJson(receiveValue.toString(), this.$t('connections.receivedMsg')) + let jsonValue: string | undefined + try { + jsonValue = validFormatJson(receiveValue.toString(), this.$t('connections.receivedMsg')) + } catch (error) { + this.$message.error((error as Error).toString()) + } if (jsonValue) { return jsonValue }