Skip to content

Commit

Permalink
feat: enhance error prompt message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Nov 6, 2024
1 parent 182183f commit d28ec23
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ tasks.named("processResources").configure {
}

halo {
version = "2.19.3"
version = "2.20"
}

haloPlugin {
Expand Down
14 changes: 12 additions & 2 deletions ui/src/components/sources/PexelsImages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { useConfig } from '@/composables/use-config'
import { useImageControl } from '@/composables/use-image-control'
import { DEFAULT_PER_PAGE } from '@/constants'
import type { PexelsPhoto, PexelsPhotoResponse } from '@/types'
import { VButton, VLoading } from '@halo-dev/components'
import { Toast, VButton, VLoading } from '@halo-dev/components'
import type { AttachmentLike } from '@halo-dev/console-shared'
import { useQuery } from '@tanstack/vue-query'
import axios from 'axios'
import axios, { AxiosError } from 'axios'
import { ref, watch } from 'vue'
import DownloadButton from '../base/DownloadButton.vue'
import DownloadModeSwitcher from '../base/DownloadModeSwitcher.vue'
Expand Down Expand Up @@ -61,8 +61,18 @@ const { isFetching } = useQuery({
})
return data as PexelsPhotoResponse
},
retry: 0,
onSuccess(data) {
images.value = [...images.value, ...data.photos]
},
onError(e) {
if (e instanceof AxiosError) {
Toast.error(e.response?.data)
return
}
if (e instanceof Error) {
Toast.error(e.message)
}
}
})
Expand Down
20 changes: 18 additions & 2 deletions ui/src/components/sources/PixabayImages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { useConfig } from '@/composables/use-config'
import { useImageControl } from '@/composables/use-image-control'
import { DEFAULT_PER_PAGE } from '@/constants'
import type { PixabayHit, PixabayResponse } from '@/types'
import { VButton, VLoading } from '@halo-dev/components'
import { Toast, VButton, VLoading } from '@halo-dev/components'
import type { AttachmentLike } from '@halo-dev/console-shared'
import { useQuery } from '@tanstack/vue-query'
import axios from 'axios'
import axios, { AxiosError } from 'axios'
import { ref, watch } from 'vue'
import DownloadButton from '../base/DownloadButton.vue'
import DownloadModeSwitcher from '../base/DownloadModeSwitcher.vue'
Expand Down Expand Up @@ -188,8 +188,24 @@ const { isFetching } = useQuery({
})
return data as PixabayResponse
},
retry: 0,
onSuccess(data) {
images.value = [...images.value, ...data.hits]
},
onError(e) {
if (e instanceof AxiosError) {
const data = e.response?.data
if ('detail' in data) {
Toast.error(data.detail)
} else {
Toast.error(data)
}
return
}
if (e instanceof Error) {
Toast.error(e.message)
}
}
})
Expand Down
24 changes: 22 additions & 2 deletions ui/src/components/sources/UnsplashImages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { UnsplashV1alpha1Api } from '@/api/generated'
import { useConfig } from '@/composables/use-config'
import { useImageControl } from '@/composables/use-image-control'
import { DEFAULT_PER_PAGE } from '@/constants'
import { VButton, VLoading } from '@halo-dev/components'
import { Toast, VButton, VLoading } from '@halo-dev/components'
import type { AttachmentLike } from '@halo-dev/console-shared'
import { useQuery } from '@tanstack/vue-query'
import axios from 'axios'
import axios, { AxiosError } from 'axios'
import type { Basic as Photo } from 'unsplash-js/dist/methods/photos/types'
import type { Photos } from 'unsplash-js/dist/methods/search/types/response'
import type { Basic as Topic } from 'unsplash-js/dist/methods/topics/types'
Expand Down Expand Up @@ -60,10 +60,20 @@ const { data: topics } = useQuery<Topic[] | undefined>({
})
return (data as Topic[]) || []
},
retry: 0,
onSuccess(data) {
if (data?.length) {
selectedTopicId.value = data[0].id
}
},
onError(e) {
if (e instanceof AxiosError) {
Toast.error(e.response?.data)
return
}
if (e instanceof Error) {
Toast.error(e.message)
}
}
})
Expand Down Expand Up @@ -101,9 +111,19 @@ const { isFetching } = useQuery({
return (data as Photo[]) || []
},
retry: 0,
onSuccess(data) {
images.value = [...images.value, ...data]
},
onError(e) {
if (e instanceof AxiosError) {
Toast.error(e.response?.data)
return
}
if (e instanceof Error) {
Toast.error(e.message)
}
},
keepPreviousData: true
})
Expand Down

0 comments on commit d28ec23

Please sign in to comment.