fix: show a proper error message on download failure (#1345)
This commit is contained in:
parent
f11a59bece
commit
d0edcbb8b9
@ -22,8 +22,12 @@ export default function EventListenerWrapper({ children }: PropsWithChildren) {
|
||||
const modelsRef = useRef(models)
|
||||
|
||||
const { setDownloadedModels, downloadedModels } = useGetDownloadedModels()
|
||||
const { setDownloadState, setDownloadStateSuccess, setDownloadStateFailed } =
|
||||
useDownloadState()
|
||||
const {
|
||||
setDownloadState,
|
||||
setDownloadStateSuccess,
|
||||
setDownloadStateFailed,
|
||||
setDownloadStateCancelled,
|
||||
} = useDownloadState()
|
||||
const downloadedModelRef = useRef(downloadedModels)
|
||||
|
||||
useEffect(() => {
|
||||
@ -52,13 +56,18 @@ export default function EventListenerWrapper({ children }: PropsWithChildren) {
|
||||
|
||||
window.electronAPI.onFileDownloadError(
|
||||
async (_event: string, state: any) => {
|
||||
if (state.err?.message !== 'aborted')
|
||||
console.error('Download error', state)
|
||||
const modelName = await baseName(state.fileName)
|
||||
const model = modelsRef.current.find(
|
||||
(model) => modelBinFileName(model) === modelName
|
||||
)
|
||||
if (model) setDownloadStateFailed(model.id)
|
||||
if (model) {
|
||||
if (state.err?.message !== 'aborted') {
|
||||
console.error('Download error', state)
|
||||
setDownloadStateFailed(model.id, state.err.message)
|
||||
} else {
|
||||
setDownloadStateCancelled(model.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -29,7 +29,27 @@ const setDownloadStateSuccessAtom = atom(null, (get, set, modelId: string) => {
|
||||
})
|
||||
})
|
||||
|
||||
const setDownloadStateFailedAtom = atom(null, (get, set, modelId: string) => {
|
||||
const setDownloadStateFailedAtom = atom(
|
||||
null,
|
||||
(get, set, modelId: string, error: string) => {
|
||||
const currentState = { ...get(modelDownloadStateAtom) }
|
||||
const state = currentState[modelId]
|
||||
if (!state) {
|
||||
console.debug(`Cannot find download state for ${modelId}`)
|
||||
toaster({
|
||||
title: 'Download Failed',
|
||||
description: `Model ${modelId} download failed: ${error}`,
|
||||
type: 'error',
|
||||
})
|
||||
return
|
||||
}
|
||||
delete currentState[modelId]
|
||||
set(modelDownloadStateAtom, currentState)
|
||||
}
|
||||
)
|
||||
const setDownloadStateCancelledAtom = atom(
|
||||
null,
|
||||
(get, set, modelId: string) => {
|
||||
const currentState = { ...get(modelDownloadStateAtom) }
|
||||
const state = currentState[modelId]
|
||||
if (!state) {
|
||||
@ -38,17 +58,20 @@ const setDownloadStateFailedAtom = atom(null, (get, set, modelId: string) => {
|
||||
title: 'Cancel Download',
|
||||
description: `Model ${modelId} cancel download`,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
delete currentState[modelId]
|
||||
set(modelDownloadStateAtom, currentState)
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
export function useDownloadState() {
|
||||
const modelDownloadState = useAtomValue(modelDownloadStateAtom)
|
||||
const setDownloadState = useSetAtom(setDownloadStateAtom)
|
||||
const setDownloadStateSuccess = useSetAtom(setDownloadStateSuccessAtom)
|
||||
const setDownloadStateFailed = useSetAtom(setDownloadStateFailedAtom)
|
||||
const setDownloadStateCancelled = useSetAtom(setDownloadStateCancelledAtom)
|
||||
|
||||
const downloadStates: DownloadState[] = []
|
||||
for (const [, value] of Object.entries(modelDownloadState)) {
|
||||
@ -61,6 +84,7 @@ export function useDownloadState() {
|
||||
setDownloadState,
|
||||
setDownloadStateSuccess,
|
||||
setDownloadStateFailed,
|
||||
setDownloadStateCancelled,
|
||||
downloadStates,
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user