Skip to content

Commit

Permalink
fix: Added error handling for json content parser
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed May 9, 2024
1 parent 29cd854 commit ad0160e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/sharedData/visualization/components/VisualizationMapLayer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import bbox from '@turf/bbox';
import _ from 'lodash/fp';
import logger from 'terraso-client-shared/monitoring/logger';
import { Box, Portal, Stack, Typography } from '@mui/material';

import Layer from 'gis/components/Layer';
Expand Down Expand Up @@ -56,9 +57,18 @@ const getSourceBounds = async (map, sourceId) => {
);
};

const parseJson = content => {
try {
return JSON.parse(content);
} catch (error) {
logger.warn('Failed to parse popup json content', error);
}
return [];
};

const PopupContent = props => {
const { data } = props;
const fields = JSON.parse(data.fields);
const fields = parseJson(data.fields);
const title = data.title;

return (
Expand Down

0 comments on commit ad0160e

Please sign in to comment.