From 88fd4698d07e5bfd00c598b606f2d96457ea5d5a Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 22 Jan 2021 14:23:05 -0800 Subject: [PATCH] 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! --- src/app/components/SpeciesColorPicker.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/components/SpeciesColorPicker.js b/src/app/components/SpeciesColorPicker.js index 768c483..f65cdfa 100644 --- a/src/app/components/SpeciesColorPicker.js +++ b/src/app/components/SpeciesColorPicker.js @@ -3,7 +3,7 @@ import gql from "graphql-tag"; import { useQuery } from "@apollo/client"; 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. @@ -267,7 +267,16 @@ function getPairByte(valids, speciesId, colorId) { const colorIndex = colorId - 1; const numColors = valids.getUint8(1); const pairByteIndex = speciesIndex * numColors + colorIndex + 2; - return valids.getUint8(pairByteIndex); + try { + 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) {