feat: added more info to error messages

Signed-off-by: Varun Raj <mailme@varunraj.in>
This commit is contained in:
Varun Raj committed 2024-09-04 19:33:51 +05:30
1 parent 30526e8e46
commit 1013231f00
6 files changed
+44 -22

No files matched your search

-3
View File
@@ -33,7 +33,6 @@ export function LoginForm(
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null); const [errorMessage, setErrorMessage] = useState<string | null>(null);
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFormData({ ...formData, [e.target.id]: e.target.value }) setFormData({ ...formData, [e.target.id]: e.target.value })
} }
@@ -50,7 +49,6 @@ export function LoginForm(
}) })
} }
return ( return (
<> <>
<Head> <Head>
@@ -96,7 +94,6 @@ export function LoginForm(
Login with OAuth Login with OAuth
</Button> </Button>
</form> </form>
</CardContent> </CardContent>
</Card> </Card>
</div> </div>
+29 -10
View File
@@ -9,12 +9,14 @@ import Loader from "../ui/loader";
import { ArrowRight, TriangleAlert } from "lucide-react"; import { ArrowRight, TriangleAlert } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { LoginForm } from "../auth/LoginForm"; import { LoginForm } from "../auth/LoginForm";
import { useConfig } from "@/contexts/ConfigContext";
type RootLayoutProps = { type RootLayoutProps = {
children: ReactNode; children: ReactNode;
}; };
export default function RootLayout({ children }: RootLayoutProps) { export default function RootLayout({ children }: RootLayoutProps) {
const { immichURL, exImmichUrl } = useConfig();
const [user, setUser] = useState<IUser | null>(null); const [user, setUser] = useState<IUser | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState<{ const [errorMessage, setErrorMessage] = useState<{
@@ -40,6 +42,7 @@ export default function RootLayout({ children }: RootLayoutProps) {
fetchData(); fetchData();
}, []); }, []);
if (loading) return <Loader />; if (loading) return <Loader />;
if (errorMessage) if (errorMessage)
return ( return (
@@ -49,16 +52,32 @@ export default function RootLayout({ children }: RootLayoutProps) {
title={errorMessage.error} title={errorMessage.error}
description={errorMessage.message} description={errorMessage.message}
action={ action={
<Link <div className="flex flex-col items-center">
className="flex items-center gap-2 text-xs" <Link
href={ className="flex items-center gap-2 text-xs"
"https://github.com/varun-raj/immich-power-tools?tab=readme-ov-file#-getting-started" href={
} "https://github.com/varun-raj/immich-power-tools?tab=readme-ov-file#-getting-started"
target="_blank" }
> target="_blank"
Setup Instructions >
<ArrowRight className="h-4 w-4" /> Setup Instructions
</Link> <ArrowRight className="h-4 w-4" />
</Link>
<div className="text-xs flex flex-col gap-4 py-4 w-full">
<div className="text-center">
<p className="text-muted-foreground font-mono">Connected to (External)</p>
<Link href={exImmichUrl || ""} target="_blank" className="font-mono">
{exImmichUrl || "Not Set"}
</Link>
</div>
<div className="text-center">
<p className="text-muted-foreground font-mono">Connected to (Internal)</p>
<Link href={immichURL} target="_blank" className="font-mono">
{immichURL}
</Link>
</div>
</div>
</div>
} }
/> />
</div> </div>
+2
View File
@@ -1,3 +1,5 @@
import { useConfig } from '@/contexts/ConfigContext';
import { Link } from 'lucide-react';
import React from 'react' import React from 'react'
interface ErrorBlockProps { interface ErrorBlockProps {
+1
View File
@@ -6,6 +6,7 @@ import { ENV } from "@/config/environment";
import ConfigContext from "@/contexts/ConfigContext"; import ConfigContext from "@/contexts/ConfigContext";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { getMe } from "@/handlers/api/user.handler"; import { getMe } from "@/handlers/api/user.handler";
import { db } from "@/config/db";
interface AppPropsWithProps extends AppProps { interface AppPropsWithProps extends AppProps {
props: { props: {
@@ -24,8 +24,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.status(403).json({ message: 'Forbidden' }) return res.status(403).json({ message: 'Forbidden' })
} }
console.log('currentUser.accessToken:', currentUser)
try { try {
// Forward the request to the target API // Forward the request to the target API
const response = await fetch(targetUrl, { const response = await fetch(targetUrl, {
+12 -7
View File
@@ -1,5 +1,6 @@
// pages/api/proxy.js // pages/api/proxy.js
import { ENV } from "@/config/environment";
import { getCurrentUser } from "@/handlers/serverUtils/user.utils"; import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
@@ -13,14 +14,18 @@ export default async function handler(
req: NextApiRequest, req: NextApiRequest,
res: NextApiResponse res: NextApiResponse
) { ) {
if (req.method !== "GET") if (req.method !== "GET") {
return res.status(405).json({ message: "Method Not Allowed" });
return res.status(405).json({ message: "Method Not Allowed" }); }
const user = await getCurrentUser(req); try {
console.log("currentUser.accessToken:", user); const user = await getCurrentUser(req);
if (user) return res.status(200).json(user); if (user) return res.status(200).json(user);
return res.status(403).json({ message: "Forbidden" }); return res.status(403).json({ message: "Forbidden" });
} catch (error) {
return res.status(500).json(error);
}
} }