260312_01_ENH: Error 페이지 및 Redirect 페이지 구현
This commit is contained in:
@@ -45,7 +45,7 @@ const LoginPage = () => {
|
||||
const err = apiError(e);
|
||||
if (err.status === 401 || err.status === 403) setError("아이디 또는 비밀번호를 다시 확인해주세요.");
|
||||
else if (err.code === NONE_HTTP_ERROR) setError("알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해주세요.");
|
||||
else setError(`로그인에 실패했습니다. (status: ${err.status})`);
|
||||
else setError(`로그인에 실패했습니다. (${err.message})`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
37
src/app/(pages)/redirect/[slug]/page.tsx
Normal file
37
src/app/(pages)/redirect/[slug]/page.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import RedirectLanding from "@/components/external/RedirectLanding";
|
||||
import {notFound} from "next/navigation";
|
||||
import {ALLOW_REDIRECT} from "@/const/commonConst";
|
||||
import {RedirectSlug} from "@/types/common";
|
||||
|
||||
type redirectPageProps = {
|
||||
params: Promise<{ slug: string }>;
|
||||
searchParams?: Promise<Record<string, string | string[] | undefined>>;
|
||||
}
|
||||
|
||||
const toRedirectSlug = (slug: string): RedirectSlug | null => {
|
||||
return ALLOW_REDIRECT.has(slug.toLowerCase()) ? (slug.toLowerCase() as RedirectSlug) : null;
|
||||
}
|
||||
|
||||
const redirectPage = async ({
|
||||
params,
|
||||
searchParams,
|
||||
}: redirectPageProps) => {
|
||||
const { slug } = await params;
|
||||
const sp = searchParams ? await searchParams : undefined;
|
||||
|
||||
//미들 웨어에서 처리
|
||||
console.log(sp);
|
||||
|
||||
const redirectSlug = toRedirectSlug(slug);
|
||||
|
||||
console.log(redirectSlug);
|
||||
|
||||
|
||||
if (!redirectSlug) notFound();
|
||||
|
||||
return (
|
||||
<RedirectLanding redirectSlug={redirectSlug} />
|
||||
)
|
||||
}
|
||||
|
||||
export default redirectPage;
|
||||
35
src/app/(pages)/redirect/error/page.tsx
Normal file
35
src/app/(pages)/redirect/error/page.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import ErrorPage from "@/components/external/Error";
|
||||
import {ErrorCode} from "@/types/common";
|
||||
|
||||
function toErrorCode(raw: string | undefined): ErrorCode {
|
||||
if (raw === "500") return "500";
|
||||
// fetch_error, 기타 알 수 없는 코드 → 500으로 처리
|
||||
if (raw && raw !== "404") return "500";
|
||||
return "404";
|
||||
}
|
||||
|
||||
type RedirectErrorPageProps = {
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
||||
};
|
||||
|
||||
const RedirectErrorPage = async ({ searchParams }: RedirectErrorPageProps) => {
|
||||
const sp = await searchParams;
|
||||
|
||||
console.log(sp)
|
||||
|
||||
const code = toErrorCode(sp.code as string | undefined);
|
||||
const sid = (sp.sid as string | undefined) ?? "";
|
||||
|
||||
return (
|
||||
<ErrorPage
|
||||
code={code}
|
||||
errorDescription={
|
||||
sid
|
||||
? `오류가 발생했습니다. 관리자에게 문의할 경우 아래 코드를 전달해 주세요.\n리스트 ID : ${sid}`
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default RedirectErrorPage
|
||||
Reference in New Issue
Block a user