From 8f845e726499b86f78f8e10c0dacaaf3314724d4 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 3 Sep 2021 13:23:19 -0700 Subject: [PATCH] Better handle null imageUrl in /api/outfitImage Oops, right, this is a nullable field! Before this change, a null here would crash the function. Now, it returns a helpful error message! --- api/outfitImage.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/outfitImage.js b/api/outfitImage.js index 4738049..d93b5d2 100644 --- a/api/outfitImage.js +++ b/api/outfitImage.js @@ -157,12 +157,14 @@ const GRAPHQL_QUERY = gql` outfit(id: $outfitId) { petAppearance { layers { + id imageUrl(size: $size) } ...PetAppearanceForGetVisibleLayers } itemAppearances { layers { + id imageUrl(size: $size) } ...ItemAppearanceForGetVisibleLayers @@ -198,6 +200,13 @@ async function loadLayerUrlsForSavedOutfit(outfitId, size) { const { petAppearance, itemAppearances } = data.outfit; const visibleLayers = getVisibleLayers(petAppearance, itemAppearances); + + for (const layer of visibleLayers) { + if (!layer.imageUrl) { + throw new Error(`layer ${layer.id} has no imageUrl for size ${size}`); + } + } + return visibleLayers .sort((a, b) => a.depth - b.depth) .map((layer) => layer.imageUrl);