diff --git a/pages/api/outfitImage.js b/pages/api/outfitImage.js index 5eb63f2..de36b9a 100644 --- a/pages/api/outfitImage.js +++ b/pages/api/outfitImage.js @@ -84,7 +84,7 @@ async function handle(req, res) { return reject( res, `Error loading data for outfit ${outfitId}: ${e.message}`, - 500 + 500, ); } } else if (req.query.id) { @@ -101,7 +101,7 @@ async function handle(req, res) { return reject( res, `Error loading data for outfit ${outfitId}: ${e.message}`, - 500 + 500, ); } @@ -188,7 +188,7 @@ async function loadLayerUrlsForSavedOutfit(outfitId, size) { if (errors && errors.length > 0) { throw new Error( - `GraphQL Error: ${errors.map((e) => e.message).join(", ")}` + `GraphQL Error: ${errors.map((e) => e.message).join(", ")}`, ); } @@ -197,17 +197,20 @@ async function loadLayerUrlsForSavedOutfit(outfitId, size) { } const { petAppearance, itemAppearances } = data.outfit; - const visibleLayers = getVisibleLayers(petAppearance, itemAppearances); + const visibleLayers = getVisibleLayers(petAppearance, itemAppearances); + visibleLayers.sort((a, b) => a.depth - b.depth); + + const imageUrls = []; for (const layer of visibleLayers) { if (!layer.imageUrl) { - throw new Error(`layer ${layer.id} has no imageUrl for size ${size}`); + console.warn(`layer ${layer.id} has no imageUrl for size ${size}`); + continue; } + imageUrls.push(layer.imageUrl); } - return visibleLayers - .sort((a, b) => a.depth - b.depth) - .map((layer) => layer.imageUrl); + return imageUrls; } async function loadUpdatedAtForSavedOutfit(outfitId) { @@ -230,7 +233,7 @@ function reject(res, message, status = 400) { async function handleWithBeeline(req, res) { beeline.withTrace( { name: "api/outfitImage", operation_name: "api/outfitImage" }, - () => handle(req, res) + () => handle(req, res), ); }