Skip to content
Merged
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
16 changes: 16 additions & 0 deletions src/runtime/components/places.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
import { computed, ref, watch } from 'vue'
import { gql } from 'graphql-tag'
import { useQuery } from '@vue/apollo-composable'
// @ts-ignore - #imports is a Nuxt virtual module
import { createError } from '#imports'

// Types
interface PlaceResponse {
Expand Down Expand Up @@ -191,6 +193,20 @@ const { result, loading } = useQuery<{ places: PlaceResponse[] }>(

const places = computed<Place[]>(() => result.value?.places || [])

// Watch for empty places and throw 404 error
watch([places, loading], ([newPlaces, isLoading]) => {
// Only check after loading is complete and if we have query filters
if (!isLoading && (props.adm0 || props.adm1 || props.city)) {
if (newPlaces.length === 0) {
throw createError({
statusCode: 404,
statusMessage: 'Place not found',
fatal: true
})
}
}
})

const placeTitleName = computed<string>(() => {
if (props.city && props.adm1 && props.adm0) {
return `${props.city}, ${props.adm1}, ${props.adm0}`
Expand Down