Skip to content

Commit

Permalink
Catching GraphQLErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
sjsikora committed Jul 31, 2023
1 parent a0a8c79 commit 883df9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/graphql/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,6 @@ export const getClimbById = async (id: string): Promise<ClimbType> => {
id
},
fetchPolicy: 'no-cache'
})
}).catch(e => { throw new Error(e) })
return res.data.climb
}
12 changes: 12 additions & 0 deletions src/pages/climbs/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -360,6 +361,17 @@ export const getStaticProps: GetStaticProps<ClimbPageProps, { id: string }> = 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
Expand Down
5 changes: 5 additions & 0 deletions src/pages/crag/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,6 +94,10 @@ export const getStaticProps: GetStaticProps<CragProps, { id: string }> = 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) {
Expand Down

0 comments on commit 883df9d

Please sign in to comment.