fix(ancpi): add SearchEstate debug logging, try without uatId, add cart first

SearchEstate might need active cart and/or different headers.
Add X-Requested-With: XMLHttpRequest, make uatId optional, log raw
response (type, length, sample), and add-to-cart before searching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-23 01:27:30 +02:00
parent f92fcfd86b
commit d367b5f736
2 changed files with 43 additions and 19 deletions
+15 -10
View File
@@ -81,26 +81,31 @@ export async function GET(req: Request) {
const client = await EpayClient.create(username, password);
const countyIdx = resolveEpayCountyIndex("Cluj")!;
// Try SearchEstate with different uatId values to find what works
const results: Record<string, unknown> = {};
// Test 1: uatId=-1 (maybe "all")
results["345295_uatNeg1"] = await client.searchEstate("345295", countyIdx, -1).catch((e: Error) => ({ error: e.message }));
// First add to cart — SearchEstate might only work with active cart
let basketRowId: number | null = null;
try {
basketRowId = await client.addToCart(14200);
results["_basketRowId"] = basketRowId;
} catch (e) {
results["_cartError"] = (e as Error).message;
}
// Test 2: uatId=0
results["345295_uat0"] = await client.searchEstate("345295", countyIdx, 0).catch((e: Error) => ({ error: e.message }));
// Test SearchEstate: without uatId (optional now)
results["345295_noUat"] = await client.searchEstate("345295", countyIdx).catch((e: Error) => ({ error: e.message }));
// Test 3: uatId=24 (from spec: Cluj-Napoca is index 24)
// Test with uatId=24 (spec says Cluj-Napoca)
results["345295_uat24"] = await client.searchEstate("345295", countyIdx, 24).catch((e: Error) => ({ error: e.message }));
// Test 4: no uatId at all — modify searchEstate to support optional
// For now just try a few indices for Feleacu/Florești
results["63565_uat0"] = await client.searchEstate("63565", countyIdx, 0).catch((e: Error) => ({ error: e.message }));
results["88089_uat0"] = await client.searchEstate("88089", countyIdx, 0).catch((e: Error) => ({ error: e.message }));
// Other parcels without uatId
results["63565_noUat"] = await client.searchEstate("63565", countyIdx).catch((e: Error) => ({ error: e.message }));
results["88089_noUat"] = await client.searchEstate("88089", countyIdx).catch((e: Error) => ({ error: e.message }));
return NextResponse.json({
step: "search",
countyIdx,
basketRowId,
results,
});
}