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:
parent
b8081d98aa
commit
8f845e7264
1 changed files with 9 additions and 0 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue