Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Implementing 404 page for unknown crags and climbs #947

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading