From 883df9d5d2c73a4380414269094c596d1f4f02a1 Mon Sep 17 00:00:00 2001 From: DMRocks Date: Sun, 30 Jul 2023 17:43:35 -0700 Subject: [PATCH] Catching GraphQLErrors --- src/js/graphql/api.ts | 2 +- src/pages/climbs/[id].tsx | 12 ++++++++++++ src/pages/crag/[id].tsx | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/js/graphql/api.ts b/src/js/graphql/api.ts index f375bf9d5..dc286c31f 100644 --- a/src/js/graphql/api.ts +++ b/src/js/graphql/api.ts @@ -215,6 +215,6 @@ export const getClimbById = async (id: string): Promise => { id }, fetchPolicy: 'no-cache' - }) + }).catch(e => { throw new Error(e) }) return res.data.climb } diff --git a/src/pages/climbs/[id].tsx b/src/pages/climbs/[id].tsx index 8b31c9dcb..c402ccd3e 100644 --- a/src/pages/climbs/[id].tsx +++ b/src/pages/climbs/[id].tsx @@ -32,6 +32,7 @@ import { removeTypenameFromDisciplines } from '../../js/utils' import { TotalLengthInput } from '../../components/edit/form/TotalLengthInput' import { LegacyFAInput } from '../../components/edit/form/LegacyFAInput' import { getClimbById } from '../../js/graphql/api' +import { GraphQLError } from 'graphql/error/GraphQLError' export const CLIMB_DESCRIPTION_FORM_VALIDATION_RULES: RulesType = { maxLength: { @@ -360,6 +361,17 @@ export const getStaticProps: GetStaticProps = as } const climb = await getClimbById(params.id) + .catch((err: GraphQLError) => { + if (err.message === 'Invalid UUID.') { + return null + } + }) + + if (climb == null) { + return { + notFound: true + } + } const sortedClimbsInArea = await fetchSortedClimbsInArea(climb.ancestors[climb.ancestors.length - 1]) let leftClimb: ClimbType | null = null diff --git a/src/pages/crag/[id].tsx b/src/pages/crag/[id].tsx index 0cae799fa..ba10f71e4 100644 --- a/src/pages/crag/[id].tsx +++ b/src/pages/crag/[id].tsx @@ -11,6 +11,7 @@ import PhotoMontage from '../../components/media/PhotoMontage' import { UploadCTACragBanner } from '../../components/media/UploadCTA' import CragSummary, { Skeleton as AreaContentSkeleton } from '../../components/crag/cragSummary' import { QUERY_AREA_BY_ID } from '../../js/graphql/gql/areaById' +import { GraphQLError } from 'graphql/error/GraphQLError' interface CragProps { area: AreaType @@ -93,6 +94,10 @@ export const getStaticProps: GetStaticProps = async ( uuid: params.id }, fetchPolicy: 'no-cache' + }).catch((e: GraphQLError) => { + if (e.message === 'Invaild UUID') { + return null + } }) if (rs?.data == null || rs?.data?.area == null) {