Skip to content

Commit

Permalink
fix(connection):fix vaild-format-json error
Browse files Browse the repository at this point in the history
  • Loading branch information
ni00 authored and ysfscream committed Jul 11, 2023
1 parent 41787a6 commit ab0c603
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/components/MsgPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/validFormatJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export default (jsonStrValue: string, warnMessage?: TranslateResult) => {
if (warnMessage) {
errorMessage = `${warnMessage} ${errorMessage}`
}
throw error
throw errorMessage
}
}
8 changes: 6 additions & 2 deletions src/views/connections/ConnectionsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit ab0c603

Please sign in to comment.