Skip to content

Commit 41c97aa

Browse files
authored
Merge pull request #51 from mauchede/task/handle-api-doc-parser-error
Handle error during api documentation parsing
2 parents 3ec3d2d + 001596f commit 41c97aa

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"dependencies": {
3838
"admin-on-rest": "^1.1",
39-
"api-doc-parser": "^0.1.7",
39+
"api-doc-parser": "^0.2.0",
4040
"babel-runtime": "^6.23",
4141
"jsonld": "^0.4",
4242
"lodash.isplainobject": "^4.0.6",

src/hydra/HydraAdmin.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,70 @@ import restClient from './hydraClient';
77
class HydraAdmin extends Component {
88
static defaultProps = {
99
apiDocumentationParser,
10+
customRoutes: [],
11+
error: 'Unable to retrieve API documentation.',
12+
loading: 'Loading...',
1013
restClient,
1114
};
1215

1316
static propTypes = {
1417
apiDocumentationParser: PropTypes.func,
18+
customRoutes: PropTypes.array,
1519
entrypoint: PropTypes.string.isRequired,
20+
error: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
21+
loading: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
1622
restClient: PropTypes.func,
1723
};
1824

1925
state = {
2026
api: null,
27+
customRoutes: [],
28+
hasError: false,
29+
loaded: false,
2130
};
2231

2332
componentDidMount() {
2433
this.props
2534
.apiDocumentationParser(this.props.entrypoint)
26-
.then(api => this.setState({api}));
35+
.then(
36+
({api, customRoutes = []}) => ({
37+
api,
38+
customRoutes,
39+
hasError: false,
40+
loaded: true,
41+
}),
42+
({api, customRoutes = []}) => ({
43+
api,
44+
customRoutes,
45+
hasError: true,
46+
loaded: true,
47+
}),
48+
)
49+
.then(this.setState.bind(this));
2750
}
2851

2952
render() {
30-
if (null === this.state.api) {
31-
return <span>Loading...</span>;
53+
if (false === this.state.loaded) {
54+
return 'function' === typeof this.props.loading
55+
? <this.props.loading />
56+
: <span className="loading">
57+
{this.props.loading}
58+
</span>;
59+
}
60+
61+
if (true === this.state.hasError) {
62+
return 'function' === typeof this.props.error
63+
? <this.props.error />
64+
: <span className="error">
65+
{this.props.error}
66+
</span>;
3267
}
3368

3469
return (
3570
<AdminBuilder
3671
{...this.props}
3772
api={this.state.api}
73+
customRoutes={this.props.customRoutes.concat(this.state.customRoutes)}
3874
restClient={this.props.restClient(this.state.api)}
3975
/>
4076
);

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ anymatch@^1.3.0:
115115
arrify "^1.0.0"
116116
micromatch "^2.1.5"
117117

118-
api-doc-parser@^0.1.7:
119-
version "0.1.7"
120-
resolved "https://registry.yarnpkg.com/api-doc-parser/-/api-doc-parser-0.1.7.tgz#b55697a92b425b2118e7dcd14f9d444b7e10f673"
118+
api-doc-parser@^0.2.0:
119+
version "0.2.0"
120+
resolved "https://registry.yarnpkg.com/api-doc-parser/-/api-doc-parser-0.2.0.tgz#7751ec1b7b377cd91be7698b360b7829bb234c33"
121121
dependencies:
122122
babel-runtime "^6.23.0"
123123
jsonld "^0.4.11"

0 commit comments

Comments
 (0)