Auto detect JSON and fix editor crashing on invalid JSON

This commit is contained in:
Gregory Schier 2016-09-28 13:37:53 -07:00
parent 418437aa6c
commit 9d242ab836

View File

@ -49,13 +49,23 @@ class ResponseViewer extends Component {
/> />
); );
case PREVIEW_MODE_SOURCE: case PREVIEW_MODE_SOURCE:
let mode = contentType;
try {
// FEATURE: Detect JSON even without content-type
contentType.indexOf('json') === -1 && JSON.parse(body);
mode = 'application/json';
} catch (e) {
// Nothing
}
return ( return (
<Editor <Editor
value={body || ''} value={body || ''}
updateFilter={updateFilter} updateFilter={updateFilter}
filter={filter} filter={filter}
autoPrettify={true} autoPrettify={true}
mode={contentType} mode={mode}
readOnly={true} readOnly={true}
lineWrapping={editorLineWrapping} lineWrapping={editorLineWrapping}
fontSize={editorFontSize} fontSize={editorFontSize}