From 53be4e7d109720079f9abdc0ed5f36834ecbbe95 Mon Sep 17 00:00:00 2001 From: st-angelo-adobe Date: Thu, 5 Sep 2024 11:23:00 +0300 Subject: [PATCH] MWPW-157845: Fixed no aggregated rating message --- acrobat/blocks/rnr/rnr.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/acrobat/blocks/rnr/rnr.js b/acrobat/blocks/rnr/rnr.js index 20a59beb..57e08f0e 100644 --- a/acrobat/blocks/rnr/rnr.js +++ b/acrobat/blocks/rnr/rnr.js @@ -121,14 +121,19 @@ function loadRnrData() { }; return fetch(`${RNR_API_URL}/reviews?assetType=ACROBAT&assetId=${metadata.verb}`, { headers }) - .then(async (result) => { - if (!result.ok) { - const res = await result.json(); + .then(async (response) => { + if (!response.ok) { + const res = await response.json(); throw new Error(res.message); } - return result.json(); + return response.json(); }) - .then(({ aggregatedRating }) => { + .then((result) => { + const { aggregatedRating } = result; + if (!aggregatedRating) { + window.lana?.log('No aggregated rating found for this assset.'); + return; + } rnrData.average = aggregatedRating.overallRating; rnrData.votes = Object.keys(aggregatedRating.ratingHistogram).reduce( (total, key) => total + aggregatedRating.ratingHistogram[key],