fix: show error messages when tracks fail to download
This commit is contained in:
@@ -33,7 +33,7 @@ export const downloadTrack = createAsyncThunk(
|
||||
// Then convert the MIME-type to an extension
|
||||
const extension = MimeTypes[contentType as keyof typeof MimeTypes];
|
||||
if (!extension) {
|
||||
throw new Error('Jellyfin returned an unrecognized MIME-type');
|
||||
throw new Error(`Unsupported MIME-type ${contentType}`);
|
||||
}
|
||||
|
||||
// Then generate the proper location
|
||||
@@ -74,7 +74,7 @@ export const removeDownloadedTrack = createAsyncThunk(
|
||||
}
|
||||
|
||||
// Then unlink the file, if it exists
|
||||
if (await exists(download.location)) {
|
||||
if (download.location && await exists(download.location)) {
|
||||
return unlink(download.location);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createSlice, Dictionary, EntityId } from '@reduxjs/toolkit';
|
||||
import {
|
||||
completeDownload,
|
||||
downloadAdapter,
|
||||
downloadTrack,
|
||||
failDownload,
|
||||
initializeDownload,
|
||||
progressDownload,
|
||||
@@ -49,6 +50,7 @@ const downloads = createSlice({
|
||||
...action.payload,
|
||||
isFailed: false,
|
||||
isComplete: true,
|
||||
error: undefined,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -67,6 +69,20 @@ const downloads = createSlice({
|
||||
}
|
||||
});
|
||||
});
|
||||
builder.addCase(downloadTrack.rejected, (state, action) => {
|
||||
downloadAdapter.upsertOne(state, {
|
||||
id: action.meta.arg,
|
||||
isComplete: false,
|
||||
isFailed: true,
|
||||
progress: 0,
|
||||
error: action.error.message,
|
||||
});
|
||||
|
||||
// Remove the item from the queue
|
||||
const newSet = new Set(state.queued);
|
||||
newSet.delete(action.meta.arg);
|
||||
state.queued = Array.from(newSet);
|
||||
});
|
||||
builder.addCase(removeDownloadedTrack.fulfilled, (state, action) => {
|
||||
// Remove the download if it exists
|
||||
downloadAdapter.removeOne(state, action.meta.arg);
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface DownloadEntity {
|
||||
isFailed: boolean;
|
||||
isComplete: boolean;
|
||||
size?: number;
|
||||
location: string;
|
||||
location?: string;
|
||||
jobId?: number;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user