mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-25 08:32:27 -04:00
Rework error provider
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { ReactElement } from "react";
|
||||
import { ErrorView, OfflineView } from "~/ui/errors";
|
||||
import { useSetError } from "~/providers/error-provider";
|
||||
import { ErrorView } from "~/ui/errors";
|
||||
import { type QueryIdentifier, useFetch } from "./query";
|
||||
|
||||
export const Fetch = <Data,>({
|
||||
@@ -12,9 +13,17 @@ export const Fetch = <Data,>({
|
||||
Loader: () => ReactElement;
|
||||
}): JSX.Element | null => {
|
||||
const { data, isPaused, error } = useFetch(query);
|
||||
const setError = useSetError();
|
||||
|
||||
if (error) return <ErrorView error={error} />;
|
||||
if (isPaused) return <OfflineView />;
|
||||
if (error) {
|
||||
if (error.status === 401 || error.status === 403) {
|
||||
setError({ key: "unauthorized", error });
|
||||
}
|
||||
return <ErrorView error={error} />;
|
||||
}
|
||||
if (isPaused) {
|
||||
setError({ key: "offline" });
|
||||
}
|
||||
if (!data) return <Loader />;
|
||||
return <Render {...data} />;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user