Better handling for getPairByte errors

I'm not sure why, but people are seeing errors when reading from the /api/validPetPoses binary blob. I think it's the picker not handling loading states well?

In this change, we start by just giving it graceful handling, and improving the logging. I'll also try to fix the cause in the next change!
This commit is contained in:
Emi Matchu 2021-01-22 14:23:05 -08:00
parent fca3ccf0a0
commit 88fd4698d0

View file

@ -3,7 +3,7 @@ import gql from "graphql-tag";
import { useQuery } from "@apollo/client"; import { useQuery } from "@apollo/client";
import { Box, Flex, Select, Text, useColorModeValue } from "@chakra-ui/react"; import { Box, Flex, Select, Text, useColorModeValue } from "@chakra-ui/react";
import { Delay, useFetch } from "../util"; import { Delay, logAndCapture, useFetch } from "../util";
/** /**
* SpeciesColorPicker lets the user pick the species/color of their pet. * SpeciesColorPicker lets the user pick the species/color of their pet.
@ -267,7 +267,16 @@ function getPairByte(valids, speciesId, colorId) {
const colorIndex = colorId - 1; const colorIndex = colorId - 1;
const numColors = valids.getUint8(1); const numColors = valids.getUint8(1);
const pairByteIndex = speciesIndex * numColors + colorIndex + 2; const pairByteIndex = speciesIndex * numColors + colorIndex + 2;
try {
return valids.getUint8(pairByteIndex); return valids.getUint8(pairByteIndex);
} catch (e) {
logAndCapture(
new Error(
`Error loading valid poses for species=${speciesId}, color=${colorId}: ${e.message}`
)
);
return 0;
}
} }
function pairIsValid(valids, speciesId, colorId) { function pairIsValid(valids, speciesId, colorId) {