mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 03:40:14 +00:00
Fix error handling when adding download to queue
This commit is contained in:
parent
eccf27a434
commit
b300a74669
@ -12,7 +12,6 @@ export const getDownloads = async (token: string, filter: boolean): Promise<Down
|
|||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(response.ok);
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json();
|
return response.json();
|
||||||
} else {
|
} else {
|
||||||
@ -45,11 +44,14 @@ export const sendDownloads = async (token: string, input: string): Promise<Downl
|
|||||||
},
|
},
|
||||||
method: "POST"
|
method: "POST"
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (response.ok) {
|
||||||
// throw new Error("Error adding content to the download queue.");
|
return response.json();
|
||||||
// return response.json();
|
} else if (response.status == 400) {
|
||||||
|
throw new Error("Failed to extract links. Please input IDs or URLs for videos, channels, or playlists.");
|
||||||
|
} else {
|
||||||
|
throw new Error("Failed to connect to the API.");
|
||||||
}
|
}
|
||||||
return response.json();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sendDeleteAllQueuedIgnored = async (token: string, filter: string): Promise<Download> => {
|
export const sendDeleteAllQueuedIgnored = async (token: string, filter: string): Promise<Download> => {
|
||||||
|
@ -21,9 +21,7 @@ const TA_BASE_URL = getTAUrl();
|
|||||||
type ViewStyle = "grid" | "list";
|
type ViewStyle = "grid" | "list";
|
||||||
type IgnoredStatus = boolean;
|
type IgnoredStatus = boolean;
|
||||||
type FormHidden = boolean;
|
type FormHidden = boolean;
|
||||||
type ErrorMessage = boolean;
|
type ErrorMessage = string;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
@ -72,7 +70,7 @@ const Download: NextPage = () => {
|
|||||||
|
|
||||||
const [formHidden, setFormHidden] = useState<FormHidden>(true);
|
const [formHidden, setFormHidden] = useState<FormHidden>(true);
|
||||||
const [viewStyle, setViewStyle] = useState<ViewStyle>(downloads?.config?.default_view?.downloads);
|
const [viewStyle, setViewStyle] = useState<ViewStyle>(downloads?.config?.default_view?.downloads);
|
||||||
const [errorMessage, setErrorMessage] = useState<ErrorMessage>(false);
|
const [errorMessage, setErrorMessage] = useState<ErrorMessage>(null);
|
||||||
|
|
||||||
const handleSetViewstyle = (selectedViewStyle: ViewStyle) => {
|
const handleSetViewstyle = (selectedViewStyle: ViewStyle) => {
|
||||||
setViewStyle(selectedViewStyle);
|
setViewStyle(selectedViewStyle);
|
||||||
@ -90,13 +88,14 @@ const Download: NextPage = () => {
|
|||||||
const handleSetErrorMessage = (selectedErrorMessage: ErrorMessage) => {
|
const handleSetErrorMessage = (selectedErrorMessage: ErrorMessage) => {
|
||||||
setErrorMessage(selectedErrorMessage);
|
setErrorMessage(selectedErrorMessage);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addToDownloadQueue = event => {
|
const addToDownloadQueue = event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
sendDownloads(session.ta_token.token, event.target.vid_url.value).then((response) => !response.message ? handleSetErrorMessage(false) : handleSetErrorMessage(true));
|
sendDownloads(session.ta_token.token, event.target.vid_url.value).then(() => {
|
||||||
errorMessage ? handleSetFormHidden(false) : handleSetFormHidden(true);
|
handleSetErrorMessage(null);
|
||||||
|
handleSetFormHidden(true);
|
||||||
|
})
|
||||||
|
.catch(error => handleSetErrorMessage(error.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CustomHead title="Downloads" />
|
<CustomHead title="Downloads" />
|
||||||
@ -109,14 +108,14 @@ const Download: NextPage = () => {
|
|||||||
<div id="notifications">
|
<div id="notifications">
|
||||||
{error &&
|
{error &&
|
||||||
<div className="error notification">
|
<div className="error notification">
|
||||||
<h3>{downloads?.message}</h3>
|
<h3>API Connection Error</h3>
|
||||||
<p></p>
|
<p>{error}</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
{errorMessage &&
|
{errorMessage &&
|
||||||
<div className="error notification">
|
<div className="error notification">
|
||||||
<h3>Failed to extract links.</h3>
|
<h3>Failed to add downloads to the queue.</h3>
|
||||||
<p>Not a video, channel, playlist ID or URL</p>
|
<p>{errorMessage}</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user