Skip to content

Commit

Permalink
feat(utils): improve error handling while parsing JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
yomatters committed Oct 9, 2024
1 parent bd84903 commit dd0c8ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/resource-group-affinity-group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function ResourceGroupAffinityGroup({ baseUri, infoGroupId }) {
null,
{ corsProxy: true }
);
if (!data || !data.length) return;
if (!data || data.error || !data.length) return;
const slackUri = stripTags(data[0].slack_link);
return (
<Section title="Affinity Group" icon="people-fill">
Expand Down
2 changes: 1 addition & 1 deletion src/resource-group-description.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function ResourceGroupDescription({ baseUri, infoGroupId }) {
null,
{ corsProxy: true }
);
if (!data || !data.length) return;
if (!data || data.error || !data.length) return;
const name = data[0].title;
const imageUri = `https://support.access-ci.org/${data[0].field_image}`;
const description = htmlToJsx(data[0].description);
Expand Down
7 changes: 6 additions & 1 deletion src/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export const useJSON = (
if (res.status < 200 || res.status > 299) {
setValue({ error: { status: res.status } });
} else {
const data = await res.json();
let data;
try {
data = await res.json();
} catch (error) {
setValue({ error: { message: error } });
}
setValue(data);
}
})();
Expand Down

0 comments on commit dd0c8ab

Please sign in to comment.