260312_01_ENH: Error 페이지 및 Redirect 페이지 구현

This commit is contained in:
2026-03-12 09:36:09 +09:00
parent bedcfbc9d1
commit f7ce249aa7
17 changed files with 710 additions and 6 deletions

View File

@@ -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})`);
}
}

View 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;

View 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

View File

@@ -1 +1,42 @@
//외부 설문에 뎐동 되는 API
//외부 설문에 뎐동 되는 API
import {NextRequest, NextResponse} from "next/server";
import {RouteContext} from "@/types/common";
import {createContactApi} from "@/lib/server-api";
import {errorToResponse} from "@/lib/http-util";
import {getClientIp} from "@/lib/utils";
export const POST = async (req: NextRequest, context: RouteContext) => {
try {
const { searchParams } = new URL(req.url);
const {slug = []} = await context.params;
const [action] = slug;
console.log(slug)
const sid = (searchParams.get("sid") ?? "").trim();
const allowAction = ["start", "complete", "screen", "quota"]
if(slug.length === 1 && allowAction.includes(action.toLowerCase()) && sid.length > 0){
const contactApi = await createContactApi();
const pathname = req.nextUrl.pathname;
const h = req.headers;
const log = {
remoteAddr: h.get("x-orig-ip") || getClientIp(req),
uri: h.get("x-orig-uri") || pathname,
url: h.get("x-orig-url") || req.url,
userAgent: h.get("x-orig-user-agent") || h.get("user-agent"),
referer: h.get("x-orig-referer") || h.get("referer"),
origin: h.get("x-orig-origin") || h.get("origin"),
xForwardedFor: h.get("x-forwarded-for"),
forwarded: h.get("forwarded"),
};
//Todo 수정 필요
return new NextResponse(null, { status: 204 });
}
return NextResponse.json({ message: "Not found" }, { status: 404 });
} catch (error: unknown) {
return errorToResponse(error);
}
};

9
src/app/not-found.tsx Normal file
View File

@@ -0,0 +1,9 @@
import ErrorPage from "@/components/external/Error";
const NotFound = () => {
return (
<ErrorPage code="404" />
)
}
export default NotFound