Skip to content

Commit 45f48c9

Browse files
committed
Better error handling in docs playground
1 parent 8772a87 commit 45f48c9

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

docs/src/tabs.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class TabContent extends React.Component {
4848

4949
this.state = {
5050
rjf_state: RJFEditorState.create(this.getActiveTabSchema(), this.getActiveTabData()),
51-
schemaHasError: false,
51+
schemaError: false,
5252
errorMap: {}
5353
};
5454

@@ -72,7 +72,7 @@ export class TabContent extends React.Component {
7272
if (this.props.activeTabIndex !== prevProps.activeTabIndex) {
7373
this.setState({
7474
rjf_state: RJFEditorState.create(this.getActiveTabSchema(), this.getActiveTabData()),
75-
schemaHasError: false,
75+
schemaError: false,
7676
errorMap: {},
7777
}, (state) => {
7878

@@ -110,16 +110,22 @@ export class TabContent extends React.Component {
110110
// only update form state if the schema is valid JSON
111111
try {
112112
let newSchema = JSON.parse(update.state.doc.toString());
113+
} catch (error) {
114+
this.setState({schemaError: 'Must be strictly valid JSON (no trailing commas, use double-quotes, etc.)'});
115+
return;
116+
}
117+
118+
try {
113119

114120
let newState = RJFEditorState.create(update.state.doc.toString());
115121

116-
this.setState({rjf_state: newState, schemaHasError: false}, (state) => {
122+
this.setState({rjf_state: newState, schemaError: false}, (state) => {
117123
this.updateDataEditor(this.getEditorData());
118124
});
119125
} catch (error) {
120126
// schema didn't validate
121-
if (!this.state.schemaHasError)
122-
this.setState({schemaHasError: true});
127+
if (this.state.schemaError !== true)
128+
this.setState({schemaError: true});
123129

124130
return;
125131
}
@@ -204,7 +210,13 @@ export class TabContent extends React.Component {
204210
<div className="mb-4">
205211
<p><strong>Schema</strong></p>
206212
<div ref={this.schemaEditorParentRef} className="cm-container"></div>
207-
{this.state.schemaHasError && <small className="text-danger">(!) Schema is not valid</small>}
213+
{this.state.schemaError &&
214+
<p className="text-danger">
215+
<small>(!) Schema is not valid</small>
216+
<br/>
217+
<small>{this.state.schemaError}</small>
218+
</p>
219+
}
208220
</div>
209221
<div className="mb-4">
210222
<p><strong>Output data</strong></p>

0 commit comments

Comments
 (0)