Skip to content

Commit

Permalink
Fix issue when recordType not recognized in NYPL-Core
Browse files Browse the repository at this point in the history
Currently, if the indexed recordTypeId is not recognized in NYPL-core,
serialization fails, affecting search and bib endpoints. Additionally,
it's possible for the recordType aggregation to be served without a label.
This change ensures that invalid recordTypes are removed from both bib
serialization and aggs. In general we should strive to keep indexed recordTypes
aligned with NYPL-Core; This update handles the case where they're not.
  • Loading branch information
nonword committed Dec 12, 2024
1 parent 2a4f75b commit 144682b
Show file tree
Hide file tree
Showing 3 changed files with 1,618 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/jsonld_serializers.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,11 @@ class ResourceSerializer extends JsonLdItemSerializer {
}

ResourceSerializer.getFormattedRecordType = function (recordTypeId) {
const prefLabel = recordTypes[recordTypeId]?.label
if (!prefLabel) return null
return {
'@id': recordTypeId,
prefLabel: recordTypes[recordTypeId].label
prefLabel
}
}

Expand Down Expand Up @@ -501,12 +503,16 @@ class AggregationSerializer extends JsonLdItemSerializer {
} else if (field === 'recordType') {
// Build recordType agg labels from nypl-core:
v.label = recordTypes[v.value]?.label
// Unknown recordType? Remove it:
if (!v.label) return null
} else {
v.label = v.value
}

return v
})
// Remove null aggregations (removed because found to be invalid)
.filter((agg) => agg)
} catch (e) { console.error(e) }

// Now that we've formatted buckets (into `values` prop), delete `buckets`
Expand Down
Loading

0 comments on commit 144682b

Please sign in to comment.