Skip to content

Commit

Permalink
Catch any parsing errors when formatting the value
Browse files Browse the repository at this point in the history
  • Loading branch information
hichamboushaba committed Sep 27, 2024
1 parent 1563eca commit b585623
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,13 @@ private fun JsonCustomFieldViewer(
shape = MaterialTheme.shapes.medium,
) {
val jsonFormatted = remember(customField.value) {
if (customField.value.trimStart().startsWith("[")) {
JSONArray(customField.value).toString(4)
} else {
JSONObject(customField.value).toString(4)
}
runCatching {
if (customField.value.trimStart().startsWith("[")) {
JSONArray(customField.value).toString(4)
} else {
JSONObject(customField.value).toString(4)
}
}.getOrDefault(customField.value)
}

Column(
Expand Down Expand Up @@ -347,11 +349,7 @@ private fun JsonCustomFieldViewerPreview() {
CustomField(
id = 0,
key = "key1",
value =
"""|{
| "Key": "Value"
|}
|""".trimMargin()
value = "[{\"key\": \"value\"}]"
)
),
onDismiss = {}
Expand Down

0 comments on commit b585623

Please sign in to comment.