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 },
|
||||
): Promise<AIRecommendationResponse> => {
|
||||
const base_url = process.env.BACKEND_URL || "http://localhost:8000";
|
||||
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",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
signal: options?.signal,
|
||||
});
|
||||
|
||||
if (!aiRes.ok) {
|
||||
const errorData = await aiRes.json();
|
||||
console.log("Response status:", aiRes.status);
|
||||
console.log("aiRes headers:", Object.fromEntries(aiRes.headers.entries()));
|
||||
|
||||
const errorMessage =
|
||||
errorData.detail?.[0]?.msg || "Gagal melakukan analisis AI";
|
||||
throw new Error(errorMessage);
|
||||
const text = await aiRes.text();
|
||||
console.log("Raw aiRes body:", text);
|
||||
|
||||
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