'data'
This commit is contained in:
@@ -28,7 +28,7 @@ function getApiCandidates(request: NextRequest): string[] {
|
||||
return urls.filter((u, i) => u && urls.indexOf(u) === i);
|
||||
}
|
||||
|
||||
const TIMEOUT_MS = 20000;
|
||||
const TIMEOUT_MS = 15000;
|
||||
|
||||
export async function postSalonApi(
|
||||
request: NextRequest,
|
||||
@@ -67,16 +67,18 @@ export async function postSalonApi(
|
||||
|
||||
export async function getSalonApi(
|
||||
request: NextRequest,
|
||||
path: string
|
||||
path: string,
|
||||
options?: { timeoutMs?: number }
|
||||
): Promise<{ status: number; data: unknown }> {
|
||||
const candidates = getApiCandidates(request);
|
||||
if (!candidates.length) throw new Error("PAYMENT_API_URL 未配置");
|
||||
|
||||
const timeoutMs = options?.timeoutMs ?? TIMEOUT_MS;
|
||||
let lastError: unknown = null;
|
||||
for (const apiUrl of candidates) {
|
||||
const url = `${apiUrl}${path}`;
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
||||
try {
|
||||
const res = await fetch(url, { cache: "no-store", signal: controller.signal });
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
Reference in New Issue
Block a user