Skip to content

Commit 782b307

Browse files
fix: prevents runtime error on undefined facets
It is not safe to assume that facets is going to be in the response
1 parent 77cdb7c commit 782b307

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/client.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,14 @@ export default class Client {
189189

190190
return Promise.all([baseQueryPromise, ...disjunctiveQueriesPromises]).then(
191191
([baseQueryResults, ...disjunctiveQueries]) => {
192-
disjunctiveQueries.forEach(disjunctiveQueryResults => {
193-
const [facetName, facetValue] = Object.entries(
194-
disjunctiveQueryResults.facets
195-
)[0];
196-
baseQueryResults.facets[facetName] = facetValue;
197-
});
192+
if (baseQueryResults.facets) {
193+
disjunctiveQueries.forEach(disjunctiveQueryResults => {
194+
const [facetName, facetValue] = Object.entries(
195+
disjunctiveQueryResults.facets
196+
)[0];
197+
baseQueryResults.facets[facetName] = facetValue;
198+
});
199+
}
198200
return baseQueryResults;
199201
}
200202
);

0 commit comments

Comments
 (0)