@@ -11,6 +11,7 @@ import Security from '../Security/Security';
1111import TopicsComponent from '../Topics/Topics' ;
1212import MessagesComponent from '../Messages/Messages' ;
1313import SchemasComponent from '../Schemas/Schemas' ;
14+ import ErrorComponent from '../Error/Error' ;
1415
1516import { AsyncApiWrapper } from './styled' ;
1617
@@ -23,6 +24,7 @@ export interface AsyncApiProps {
2324interface AsyncApiState {
2425 validatedSchema : AsyncApi ;
2526 validated : boolean ;
27+ error ?: Error | Error [ ] ;
2628}
2729
2830const defaultAsyncApi : AsyncApi = {
@@ -37,19 +39,26 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncApiState> {
3739 state = {
3840 validatedSchema : defaultAsyncApi ,
3941 validated : false ,
42+ error : undefined ,
4043 } ;
4144
45+ private async prepareSchema ( schema : string | Object ) {
46+ try {
47+ let validatedSchema = await this . validateSchema ( schema ) ;
48+ validatedSchema = this . beautifySchema ( validatedSchema ) ;
49+ this . setState ( { validatedSchema, validated : true , error : undefined } ) ;
50+ } catch ( e ) {
51+ this . setState ( { error : e } ) ;
52+ }
53+ }
54+
4255 async componentWillMount ( ) {
43- let validatedSchema = await this . validateSchema ( this . props . schema ) ;
44- validatedSchema = this . beautifySchema ( validatedSchema ) ;
45- this . setState ( { validatedSchema, validated : true } ) ;
56+ this . prepareSchema ( this . props . schema ) ;
4657 }
4758
4859 async componentWillReceiveProps ( nextProps : AsyncApiProps ) {
4960 if ( nextProps . schema !== this . props . schema ) {
50- let validatedSchema = await this . validateSchema ( nextProps . schema ) ;
51- validatedSchema = this . beautifySchema ( validatedSchema ) ;
52- this . setState ( { validatedSchema } ) ;
61+ this . prepareSchema ( nextProps . schema ) ;
5362 }
5463 }
5564
@@ -73,8 +82,7 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncApiState> {
7382
7483 render ( ) {
7584 const { theme, config } = this . props ;
76- const { validatedSchema, validated } = this . state ;
77-
85+ const { validatedSchema, validated, error } = this . state ;
7886 const concatenatedConfig : ConfigInterface = {
7987 ...defaultConfig ,
8088 ...config ,
@@ -83,6 +91,7 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncApiState> {
8391 ...( config && config . show ? config . show : { } ) ,
8492 } ,
8593 } ;
94+
8695 const concatenatedTheme : ThemeInterface = concatenatedConfig . disableDefaultTheme
8796 ? ( theme as ThemeInterface )
8897 : { ...defaultTheme , ...theme } ;
@@ -92,6 +101,10 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncApiState> {
92101 return (
93102 < ThemeProvider theme = { concatenatedTheme } >
94103 < AsyncApiWrapper >
104+ { this . showComponent (
105+ concatenatedConfig . showErrors && Boolean ( error ) ,
106+ < ErrorComponent error = { error } /> ,
107+ ) }
95108 { this . showComponent (
96109 concatenatedConfig . show . info && Boolean ( validatedSchema . info ) ,
97110 < InfoComponent
0 commit comments