From eccf27a4340ff52b9c7f4da6bbf02f51588ca19d Mon Sep 17 00:00:00 2001 From: n8detar Date: Thu, 21 Apr 2022 08:15:57 -0700 Subject: [PATCH] Error Handling WIP --- tubearchivist/www/src/lib/getDownloads.ts | 21 +++++++------ tubearchivist/www/src/pages/download.tsx | 37 ++++------------------- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/tubearchivist/www/src/lib/getDownloads.ts b/tubearchivist/www/src/lib/getDownloads.ts index 03286b5..81cf749 100755 --- a/tubearchivist/www/src/lib/getDownloads.ts +++ b/tubearchivist/www/src/lib/getDownloads.ts @@ -3,8 +3,8 @@ import { getTAUrl } from "./constants"; const TA_BASE_URL = getTAUrl(); -export const getDownloads = async (token: string, filter: boolean, page: number): Promise => { - const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter ? 'ignore' : 'pending'}&page=${page}`, { +export const getDownloads = async (token: string, filter: boolean): Promise => { + const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter ? 'ignore' : 'pending'}`, { headers: { Accept: "application/json", "Content-Type": "application/json", @@ -12,18 +12,19 @@ export const getDownloads = async (token: string, filter: boolean, page: number) mode: "no-cors", }, }); + console.log(response.ok); if (response.ok) { return response.json(); } else { - var error: Download = { - data: null, - config: null, - paginate: null, - message: response.statusText + " (" + response.status + ")", - } + // var error: Download = { + // data: null, + // config: null, + // paginate: null, + // message: response.statusText + " (" + response.status + ")", + // } // error = response.statusText + " (" + response.status + "); - // throw new Error(response.statusText + " (" + response.status + ")"); - return error; + throw new Error(response.statusText + " (" + response.status + ")"); + // return error; } }; diff --git a/tubearchivist/www/src/pages/download.tsx b/tubearchivist/www/src/pages/download.tsx index 44bc707..cedc31a 100755 --- a/tubearchivist/www/src/pages/download.tsx +++ b/tubearchivist/www/src/pages/download.tsx @@ -19,7 +19,6 @@ import { getTAUrl } from "../lib/constants"; const TA_BASE_URL = getTAUrl(); type ViewStyle = "grid" | "list"; -type Page = number; type IgnoredStatus = boolean; type FormHidden = boolean; type ErrorMessage = boolean; @@ -40,7 +39,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { } await queryClient.prefetchQuery(["downloads", session.ta_token.token, false], () => - getDownloads(session.ta_token.token, false, 1) + getDownloads(session.ta_token.token, false) ); return { @@ -55,7 +54,6 @@ const Download: NextPage = () => { const { data: session } = useSession(); const [ignoredStatus, setIgnoredStatus] = useState(false); - const [formHidden, setFormHidden] = useState(true); const { data: downloads, @@ -64,7 +62,7 @@ const Download: NextPage = () => { refetch, } = useQuery( ["downloads", session.ta_token.token, ignoredStatus], - () => getDownloads(session.ta_token.token, ignoredStatus, page), + () => getDownloads(session.ta_token.token, ignoredStatus), { enabled: !!session?.ta_token?.token, refetchInterval: 1500, @@ -72,10 +70,9 @@ const Download: NextPage = () => { } ); + const [formHidden, setFormHidden] = useState(true); const [viewStyle, setViewStyle] = useState(downloads?.config?.default_view?.downloads); const [errorMessage, setErrorMessage] = useState(false); - const [page, setPage] = useState(1); - const handleSetViewstyle = (selectedViewStyle: ViewStyle) => { setViewStyle(selectedViewStyle); @@ -94,12 +91,6 @@ const Download: NextPage = () => { setErrorMessage(selectedErrorMessage); }; - const handleSetPage = (selectedPage: Page) => { - console.log(page); - setPage(selectedPage); - console.log(page); - }; - const addToDownloadQueue = event => { event.preventDefault(); sendDownloads(session.ta_token.token, event.target.vid_url.value).then((response) => !response.message ? handleSetErrorMessage(false) : handleSetErrorMessage(true)); @@ -116,7 +107,7 @@ const Download: NextPage = () => {

Downloads

- {downloads?.message && + {error &&

{downloads?.message}

@@ -125,7 +116,7 @@ const Download: NextPage = () => { {errorMessage &&

Failed to extract links.

-

Not a video, channel or playlist ID or URL

+

Not a video, channel, playlist ID or URL

} { @@ -274,7 +265,7 @@ const Download: NextPage = () => {
} -

Total videos: {downloads?.data?.length ? downloads?.data?.length : 'N/A'} {!downloads?.data?.length && !downloads?.message && !ignoredStatus &&

No videos queued for download. Press rescan subscriptions to check if there are any new videos.

}

+

Total videos: {downloads?.data?.length} {!downloads?.data?.length && !downloads?.message && !ignoredStatus &&

No videos queued for download. Press rescan subscriptions to check if there are any new videos.

}

{!isLoading && !error && !downloads?.message && downloads?.data?.map((video) => { @@ -358,22 +349,6 @@ const Download: NextPage = () => { {/* {% endif %} */}
- {/* */}