michael-s-molina commented on a change in pull request #16992:
URL: https://github.com/apache/superset/pull/16992#discussion_r734478723



##########
File path: superset-frontend/src/common/hooks/apiResources/dashboards.ts
##########
@@ -17,19 +17,33 @@
  * under the License.
  */
 
-import { Dashboard, Datasource } from 'src/dashboard/types';
+import { Dashboard, DashboardMetadata, Datasource } from 'src/dashboard/types';
 import { Chart } from 'src/types/Chart';
 import { useApiV1Resource, useTransformedResource } from './apiResources';
 
 export const useDashboard = (idOrSlug: string | number) =>
   useTransformedResource(
     useApiV1Resource<Dashboard>(`/api/v1/dashboard/${idOrSlug}`),
-    dashboard => ({
-      ...dashboard,
-      metadata: dashboard.json_metadata && JSON.parse(dashboard.json_metadata),
-      position_data:
-        dashboard.position_json && JSON.parse(dashboard.position_json),
-    }),
+    dashboard => {
+      let metadata: DashboardMetadata = {};
+      let position_data = {};
+      try {
+        // need handle data parsing error
+        if (dashboard.json_metadata) {
+          metadata = JSON.parse(dashboard.json_metadata);
+        }
+        if (dashboard.position_json) {
+          position_data = JSON.parse(dashboard.position_json);
+        }
+      } catch (e) {
+        console.error('can not parse dashboard metadata.');

Review comment:
       Your change is in `transformFn` but you added a `console.log` statement 
there. To fix that, one solution would be to catch and deal with the exception 
in `useTransformedResource` as shown above.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to