diff --git a/blocks/gmo-campaign-details/gmo-campaign-details.js b/blocks/gmo-campaign-details/gmo-campaign-details.js index ca6f9e19..404e1a47 100644 --- a/blocks/gmo-campaign-details/gmo-campaign-details.js +++ b/blocks/gmo-campaign-details/gmo-campaign-details.js @@ -189,8 +189,14 @@ export default async function decorate(block) { buildProductCard(program); try { const imageObject = await searchAsset(program.programName, program.campaignName); - insertImageIntoCampaignImg(block,imageObject); - document.getElementById('totalassets').textContent = imageObject.assetCount; + if (imageObject){ + insertImageIntoCampaignImg(block,imageObject); + document.getElementById('totalassets').textContent = imageObject.assetCount; + } + else + { + document.getElementById('totalassets').textContent = 0; + } } catch (error) { console.error("Failed to load campaign image:", error); } diff --git a/blocks/gmo-campaign-list/gmo-campaign-list.js b/blocks/gmo-campaign-list/gmo-campaign-list.js index f37325fa..0b02029c 100644 --- a/blocks/gmo-campaign-list/gmo-campaign-list.js +++ b/blocks/gmo-campaign-list/gmo-campaign-list.js @@ -179,7 +179,6 @@ async function buildCampaignList(campaigns, numPerPage) { iconImage.src = imageObject.imageUrl; iconImage.alt = imageObject.imageAltText; } catch (error) { - console.error("No campaign image found:", error); } // Append the image to the campaignIcon div campaignIcon.appendChild(iconImage); diff --git a/scripts/assets.js b/scripts/assets.js index 9eb62894..37ec6233 100644 --- a/scripts/assets.js +++ b/scripts/assets.js @@ -88,9 +88,16 @@ export async function searchAsset(programName, campaignName, imageWidth = 80) { // Asset retrieved successfully const responseBody = await response.json(); const assetData = responseBody.results[0].hits[0]; - const totalAssets = responseBody.results[0].nbHits; - const thumbnailURL = await getOptimizedDeliveryUrl(assetData.assetId, assetData['repo-name'], imageWidth); - return {imageUrl : thumbnailURL, imageAltText: assetData['repo-name'], assetCount: totalAssets}; + if (assetData) + { + const totalAssets = responseBody.results[0].nbHits; + const thumbnailURL = await getOptimizedDeliveryUrl(assetData.assetId, assetData['repo-name'], imageWidth); + return {imageUrl : thumbnailURL, imageAltText: assetData['repo-name'], assetCount: totalAssets}; + } + else + { + return null; + } } // Handle other response codes throw new Error(`Failed to search asset: ${response.status} ${response.statusText}`);