@@ -78,11 +78,20 @@ class Editor extends Component {
78
78
79
79
// Fetch review again if block loaded after saving.
80
80
if ( this . props . attributes . id ) {
81
- let result = await apiFetch ( { path : `wp/v2/visualizer/${ this . props . attributes . id } ` } ) ;
82
-
83
- this . setState ( {
84
- chart : result [ 'chart_data' ]
85
- } ) ;
81
+ let result = await apiFetch ( { path : `wp/v2/visualizer/${ this . props . attributes . id } ` } ) . catch ( function ( error ) {
82
+ } ) ;
83
+
84
+ if ( result ) {
85
+ this . setState ( {
86
+ chart : result [ 'chart_data' ]
87
+ } ) ;
88
+ } else {
89
+
90
+ // if the chart is not found.
91
+ this . setState ( {
92
+ route : 'error'
93
+ } ) ;
94
+ }
86
95
}
87
96
}
88
97
@@ -92,6 +101,7 @@ class Editor extends Component {
92
101
} ) ;
93
102
94
103
let result = await apiFetch ( { path : `wp/v2/visualizer/${ id } ` } ) ;
104
+ console . log ( 'getChart' , id , result ) ;
95
105
96
106
this . setState ( {
97
107
route : 'chartSelect' ,
@@ -297,6 +307,7 @@ class Editor extends Component {
297
307
} ) ;
298
308
299
309
let result = await apiFetch ( { path : `wp/v2/visualizer/${ id } ` } ) ;
310
+ console . log ( 'getChartData' , id , result ) ;
300
311
301
312
let chart = { ...this . state . chart } ;
302
313
@@ -406,6 +417,17 @@ class Editor extends Component {
406
417
}
407
418
408
419
render ( ) {
420
+ if ( 'error' === this . state . route ) {
421
+ return (
422
+ < div className = "visualizer-settings visualizer-error" >
423
+ < div className = "visualizer-settings__title" >
424
+ < Dashicon icon = "chart-pie" />
425
+ { __ ( 'This chart is not available; it might have been deleted. Please delete this block and resubmit your chart.' ) }
426
+ </ div >
427
+ </ div >
428
+ ) ;
429
+ }
430
+
409
431
if ( 'renderChart' === this . state . route && null !== this . state . chart ) {
410
432
return (
411
433
< ChartRender
0 commit comments