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!
This commit is contained in:
Emi Matchu 2021-09-03 13:23:19 -07:00
parent b8081d98aa
commit 8f845e7264

View file

@ -157,12 +157,14 @@ const GRAPHQL_QUERY = gql`
outfit(id: $outfitId) { outfit(id: $outfitId) {
petAppearance { petAppearance {
layers { layers {
id
imageUrl(size: $size) imageUrl(size: $size)
} }
...PetAppearanceForGetVisibleLayers ...PetAppearanceForGetVisibleLayers
} }
itemAppearances { itemAppearances {
layers { layers {
id
imageUrl(size: $size) imageUrl(size: $size)
} }
...ItemAppearanceForGetVisibleLayers ...ItemAppearanceForGetVisibleLayers
@ -198,6 +200,13 @@ async function loadLayerUrlsForSavedOutfit(outfitId, size) {
const { petAppearance, itemAppearances } = data.outfit; const { petAppearance, itemAppearances } = data.outfit;
const visibleLayers = getVisibleLayers(petAppearance, itemAppearances); 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 return visibleLayers
.sort((a, b) => a.depth - b.depth) .sort((a, b) => a.depth - b.depth)
.map((layer) => layer.imageUrl); .map((layer) => layer.imageUrl);