Skip to content

Commit e87f2e6

Browse files
committed
remove double escaping
1 parent b0d927c commit e87f2e6

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/components/Preview.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,26 @@ const submit = async (form: FormInstance, fn: () => void) => {
174174
}
175175
const highlightCode = (json) => {
176176
if (json.error) {
177+
// Parse double-encoded JSON error messages to display them cleanly
178+
let errorObj = json.error
179+
180+
// Check if the error message is a JSON string that needs parsing
181+
if (errorObj.message && typeof errorObj.message === 'string') {
182+
try {
183+
const parsedMessage = JSON.parse(errorObj.message)
184+
// If successful, replace the string with the parsed object
185+
errorObj = {
186+
...errorObj,
187+
...parsedMessage
188+
}
189+
} catch (e) {
190+
// If parsing fails, keep the original error object
191+
}
192+
}
193+
177194
// Display the full OBP error object with proper formatting
178195
successResponseBody.value = hljs.lineNumbersValue(
179-
hljs.highlightAuto(JSON.stringify(json.error, null, 4), ['JSON']).value
196+
hljs.highlightAuto(JSON.stringify(errorObj, null, 4), ['JSON']).value
180197
)
181198
} else if (json) {
182199
successResponseBody.value = hljs.lineNumbersValue(

0 commit comments

Comments
 (0)