mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Auto detect JSON and fix editor crashing on invalid JSON
This commit is contained in:
parent
418437aa6c
commit
9d242ab836
@ -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}
|
||||||
|
Loading…
Reference in New Issue
Block a user