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
@@ -329,33 +329,52 @@ export class EpayClient {
async searchEstate(
identifier: string,
countyIdx: number,
uatId: number,
uatId?: number,
): Promise<EpaySearchResult[]> {
return this.retryOnAuthFail(async () => {
const body = new URLSearchParams();
body.set("identifier", identifier);
body.set("countyId", String(countyIdx));
body.set("uatId", String(uatId));
if (uatId != null && uatId >= 0) {
body.set("uatId", String(uatId));
}
const response = await this.client.post(
`${BASE_URL}/SearchEstate.action`,
body.toString(),
{
headers: { "Content-Type": "application/x-www-form-urlencoded" },
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json, text/plain, */*",
"X-Requested-With": "XMLHttpRequest",
},
timeout: DEFAULT_TIMEOUT_MS,
},
);
const data = response.data;
// Log raw response for debugging
const rawStr = typeof data === "string" ? data : JSON.stringify(data);
console.log(
`[epay] SearchEstate(${identifier}, county=${countyIdx}, uat=${uatId ?? "none"}):`,
`type=${typeof data}, len=${rawStr?.length ?? 0}, sample=${rawStr?.slice(0, 300)}`,
);
if (Array.isArray(data)) return data as EpaySearchResult[];
// Sometimes wrapped in a string
if (typeof data === "string") {
try {
const parsed = JSON.parse(data);
if (Array.isArray(parsed)) return parsed as EpaySearchResult[];
} catch {
// Not JSON
// Try JSON parse
const trimmed = data.trim();
if (trimmed.startsWith("[") || trimmed.startsWith("{")) {
try {
const parsed = JSON.parse(trimmed);
if (Array.isArray(parsed)) return parsed as EpaySearchResult[];
// Wrapped in object?
if (parsed?.results) return parsed.results as EpaySearchResult[];
} catch {
// Not JSON
}
}
}