Skip to content

Commit

Permalink
Add json field guard
Browse files Browse the repository at this point in the history
  • Loading branch information
Tammo-Feldmann committed Jun 26, 2023
1 parent 20b8aa2 commit bd4ef58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/pages/explore/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ export default function ExploreProducts({ data, location }) {
for (const doi of allShapedDoi) {
// The doi keywords are stored as a JSON string in the database
// parsing them here into an object
const keywords = JSON.parse(doi.keywords)
let keywords = []
try {
keywords = JSON.parse(doi.keywords)
} catch (e) {
console.error(`ERROR: Could not parse ${doi.keywords}`)
}

if (
keywords?.length &&
keywords != "null" &&
Expand Down
9 changes: 8 additions & 1 deletion src/utils/filter-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ export function productsFilter(selectedFilterIds) {
)

const gcmdKeywords = new Set()
const keywords = JSON.parse(product.keywords)
// guard against maleformed json fields
let keywords = []
try {
keywords = JSON.parse(product.keywords)
} catch (e) {
console.error(`ERROR: Could not parse ${product.keywords}`)
}

if (
keywords?.length &&
keywords != "null" &&
Expand Down

0 comments on commit bd4ef58

Please sign in to comment.