diff --git a/src/components/layouts/RootLayout.tsx b/src/components/layouts/RootLayout.tsx index f0efa97..bf6e093 100644 --- a/src/components/layouts/RootLayout.tsx +++ b/src/components/layouts/RootLayout.tsx @@ -6,6 +6,8 @@ import { getMe } from "@/handlers/api/user.handler"; import UserContext from "@/contexts/CurrentUserContext"; import ErrorBlock from "../shared/ErrorBlock"; import Loader from "../ui/loader"; +import { ArrowRight, TriangleAlert } from "lucide-react"; +import Link from "next/link"; type RootLayoutProps = { children: ReactNode; @@ -14,13 +16,16 @@ type RootLayoutProps = { export default function RootLayout({ children }: RootLayoutProps) { const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); - const [errorMessage, setErrorMessage] = useState(null); + const [errorMessage, setErrorMessage] = useState<{ + error: string; + message: string; + } | null>(null); const fetchData = () => { return getMe() .then(setUser) .catch((error) => { - setErrorMessage(error.message); + setErrorMessage(error); }) .finally(() => setLoading(false)); }; @@ -29,12 +34,33 @@ export default function RootLayout({ children }: RootLayoutProps) { fetchData(); }, []); - if (loading) return - if (errorMessage) return ; + if (loading) return ; + if (errorMessage) + return ( +
+ } + title={errorMessage.error} + description={errorMessage.message} + action={ + + Setup Instructions + + + } + /> +
+ ); if (!user) return null; return ( - +
{children}
diff --git a/src/components/shared/ErrorBlock.tsx b/src/components/shared/ErrorBlock.tsx index a886429..cf6605c 100644 --- a/src/components/shared/ErrorBlock.tsx +++ b/src/components/shared/ErrorBlock.tsx @@ -4,15 +4,17 @@ interface ErrorBlockProps { icon?: React.ReactNode; title?: string; description?: string; + action?: React.ReactNode; } export default function ErrorBlock( - { icon, title, description }: ErrorBlockProps + { icon, title, description, action }: ErrorBlockProps ) { return (
{icon} {title &&

{title}

} {description &&

{description}

} + {action || null}
) } diff --git a/src/config/constants/sidebarNavs.tsx b/src/config/constants/sidebarNavs.tsx index 977f1b7..a7d1b26 100644 --- a/src/config/constants/sidebarNavs.tsx +++ b/src/config/constants/sidebarNavs.tsx @@ -1,4 +1,4 @@ -import { GalleryVerticalEnd, Home, Image, LocateOff, User } from "lucide-react"; +import { GalleryVerticalEnd, Home, Image, LocateOff, MapPinX, User } from "lucide-react"; export const sidebarNavs = [ { @@ -19,6 +19,6 @@ export const sidebarNavs = [ { title: "Missing Locations", link: "/assets/missing-locations", - icon: , + icon: , }, ]; diff --git a/src/lib/api.ts b/src/lib/api.ts index c649762..bb00bf0 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -3,6 +3,34 @@ import axios from 'axios' import qs from 'qs' +const handleErrors = (error: AxiosError | any) => { + if (error.code === "ERR_BAD_RESPONSE") { + return Promise.reject({ + error: "Unable to process this request, please try again later", + message: error.code + }); + } + let errorObject = {} + if (error.response) { + const { status } = error.response + if (status === 422) { + errorObject = { + ...error.response.data, + message: 'Unable to process this request, please try again later', + } + } else { + errorObject = { + ...error.response.data, + } + } + return Promise.reject(errorObject) + } + errorObject = { + message: 'Network Error. Please check your connection and try again!', + } + return Promise.reject(errorObject) +} + export default class API { @@ -91,6 +119,6 @@ export default class API { options.headers = Object.assign(API.headers(contentType), headers) return axios(options) .then((responseJson) => responseJson.data) - // .catch(handleErrors) + .catch(handleErrors) } } diff --git a/src/pages/api/immich-proxy/[...path].ts b/src/pages/api/immich-proxy/[...path].ts index 45ad76c..791e789 100644 --- a/src/pages/api/immich-proxy/[...path].ts +++ b/src/pages/api/immich-proxy/[...path].ts @@ -41,6 +41,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) res.end() } catch (error) { console.error('Proxy error:', error) - res.status(500).json({ error: 'Internal Server Error' }) + res.status(500).json({ error }) } } \ No newline at end of file