'c1
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { postMeetupApi } from "../_paymentApi";
|
||||
|
||||
/** Vercel serverless 超时时间(秒),避免上游慢导致 502 */
|
||||
export const maxDuration = 20;
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json().catch(() => ({}));
|
||||
@@ -10,9 +13,30 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
const { status, data } = await postMeetupApi(request, "/api/meetup/check-user", { email });
|
||||
|
||||
// 上游返回 5xx 时,统一为 503 并返回友好提示,避免直接透传 502
|
||||
if (status >= 500) {
|
||||
const payload = typeof data === "object" && data !== null ? (data as Record<string, unknown>) : {};
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: (payload.error as string) || "服务暂时不可用,请稍后重试" },
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(data, { status });
|
||||
} catch (error) {
|
||||
const isTimeout =
|
||||
error instanceof Error &&
|
||||
(error.name === "AbortError" || error.message.toLowerCase().includes("abort"));
|
||||
console.error("check-user error:", error);
|
||||
return NextResponse.json({ ok: false, error: "Operation failed" }, { status: 500 });
|
||||
return NextResponse.json(
|
||||
{
|
||||
ok: false,
|
||||
error: isTimeout
|
||||
? "请求超时,请确认 payjsapi 已启动(cd payjsapi && python run.py)"
|
||||
: "服务暂时不可用,请稍后重试",
|
||||
},
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user