Added warning for invalid JSON

This commit is contained in:
Andrew Bastin
2020-06-29 14:43:50 -04:00
parent 791fe70fd3
commit 2dce318a17

View File

@@ -37,6 +37,9 @@
</button> </button>
</div> </div>
</div> </div>
<div class="valid-warning" v-if="jsonInvalid">
Invalid JSON detected
</div>
<div id="response-details-wrapper"> <div id="response-details-wrapper">
<Editor <Editor
:value="jsonBodyText" :value="jsonBodyText"
@@ -55,6 +58,13 @@
</li> </li>
</ul> </ul>
</template> </template>
<style scoped lang="scss">
.valid-warning {
color: yellow;
}
</style>
<script> <script>
import AceEditor from "../../ui/ace-editor" import AceEditor from "../../ui/ace-editor"
import { isJSONContentType } from "~/helpers/utils/contenttypes" import { isJSONContentType } from "~/helpers/utils/contenttypes"
@@ -71,6 +81,7 @@ export default {
data() { data() {
return { return {
expandResponse: false, expandResponse: false,
jsonInvalid: false,
responseBodyMaxLines: 16, responseBodyMaxLines: 16,
doneButton: '<i class="material-icons">done</i>', doneButton: '<i class="material-icons">done</i>',
downloadButton: '<i class="material-icons">save_alt</i>', downloadButton: '<i class="material-icons">save_alt</i>',
@@ -80,9 +91,11 @@ export default {
computed: { computed: {
jsonBodyText() { jsonBodyText() {
try { try {
this.jsonInvalid = false
return JSON.stringify(JSON.parse(this.responseBodyText), null, 2) return JSON.stringify(JSON.parse(this.responseBodyText), null, 2)
} catch (e) { } catch (e) {
// Most probs invalid JSON was returned, so drop prettification (should we warn ?) // Most probs invalid JSON was returned, so drop prettification (should we warn ?)
this.jsonInvalid = true
return this.responseBodyText return this.responseBodyText
} }
}, },