Skip to content

Commit

Permalink
fix: handle search errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Jan 22, 2024
1 parent 111bc0f commit 0b04976
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
31 changes: 22 additions & 9 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import { useBooruList } from '~/composables/useBooruList'
import type { Domain } from '~/assets/js/domain'
import { ArrowRightIcon } from '@heroicons/vue/24/solid'
import * as Sentry from '@sentry/vue'
import { FetchError } from 'ofetch'
const config = useRuntimeConfig()
const $authState = useState('auth-internal')
Expand Down Expand Up @@ -57,17 +59,28 @@
headers: {
Authorization: $authState.value['_token.local'] ?? undefined
},
onResponseError(context) {
if (context.response.status === 404) {
searchTagResults.value = []
return
}
toast.error(`Failed to load tags: "${context.response.statusText}"`)
}
})
//
.catch((error) => {
Sentry.captureException(error)
return error
})
if (response instanceof FetchError) {
switch (response.status) {
case 404:
toast.error('No tags found for query "' + tag + '"')
break
default:
toast.error(`Failed to load tags: "${response.message}"`)
break
}
return
}
searchTagResults.value = response.data
}
Expand Down
29 changes: 21 additions & 8 deletions pages/posts/[domain].vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import type { Domain } from '~/assets/js/domain'
import type { IPostPage } from '~/assets/js/post'
import { useInfiniteQuery } from '@tanstack/vue-query'
import { FetchError } from 'ofetch'
import * as Sentry from '@sentry/vue'
const router = useRouter()
const route = useRoute()
Expand Down Expand Up @@ -226,17 +228,28 @@
headers: {
Authorization: $authState.value['_token.local'] ?? undefined
},
}
})
//
.catch((error) => {
Sentry.captureException(error)
onResponseError(context) {
if (context.response.status === 404) {
tagResults.value = []
return
}
return error
})
toast.error(`Failed to load tags: "${context.response.statusText}"`)
if (response instanceof FetchError) {
switch (response.status) {
case 404:
toast.error('No tags found for query "' + tag + '"')
break
default:
toast.error(`Failed to load tags: "${response.message}"`)
break
}
})
return
}
tagResults.value = response.data
}
Expand Down

0 comments on commit 0b04976

Please sign in to comment.