refactor: add debugger for analyze endpoint payload clarity
This commit is contained in:
parent
b6cab8345e
commit
3e293b355b
|
|
@ -71,21 +71,33 @@ export const getAIRecommendation = async (
|
||||||
},
|
},
|
||||||
options?: { signal?: AbortSignal },
|
options?: { signal?: AbortSignal },
|
||||||
): Promise<AIRecommendationResponse> => {
|
): Promise<AIRecommendationResponse> => {
|
||||||
|
const base_url = process.env.BACKEND_URL || "http://localhost:8000";
|
||||||
console.log("Fetching to FastAPI...");
|
console.log("Fetching to FastAPI...");
|
||||||
const aiRes = await fetch(`${process.env.BACKEND_URL}/recommend`, {
|
console.log("=== AI RECOMMENDATION DEBUG ===");
|
||||||
|
console.log("Base URL:", base_url);
|
||||||
|
console.log("Full URL:", `${base_url}/recommend`);
|
||||||
|
console.log("Payload:", JSON.stringify(payload, null, 2));
|
||||||
|
|
||||||
|
const aiRes = await fetch(`${base_url}/recommend`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
signal: options?.signal,
|
signal: options?.signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!aiRes.ok) {
|
console.log("Response status:", aiRes.status);
|
||||||
const errorData = await aiRes.json();
|
console.log("aiRes headers:", Object.fromEntries(aiRes.headers.entries()));
|
||||||
|
|
||||||
const errorMessage =
|
const text = await aiRes.text();
|
||||||
errorData.detail?.[0]?.msg || "Gagal melakukan analisis AI";
|
console.log("Raw aiRes body:", text);
|
||||||
throw new Error(errorMessage);
|
|
||||||
|
if (!aiRes.ok) {
|
||||||
|
throw new Error(`HTTP ${aiRes.status}: ${text}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await aiRes.json();
|
try {
|
||||||
|
return JSON.parse(text);
|
||||||
|
} catch {
|
||||||
|
throw new Error(`Response bukan JSON: ${text}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue