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:
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 (
<Editor
value={body || ''}
updateFilter={updateFilter}
filter={filter}
autoPrettify={true}
mode={contentType}
mode={mode}
readOnly={true}
lineWrapping={editorLineWrapping}
fontSize={editorFontSize}