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) {
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);