qbo_auth: захват intuit_tid в логах и ошибках; документ требований Intuit (intuit_requirements.md)
All checks were successful
ci / test (push) Successful in 41s
ci / deploy (push) Successful in 2m49s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 20:03:33 +03:00
parent 92a85f8d9d
commit 98930c5b40
3 changed files with 44 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
import { SPECS, type EntitySpec, type Row } from "./mirror.js";
import type { FetchFn } from "./oauth.js";
import { intuitTid, type FetchFn } from "./oauth.js";
export interface Q {
query(sql: string, params?: unknown[]): Promise<{ rows: any[] }>;
@@ -55,10 +55,12 @@ export class QboSync {
const t = await this.d.getToken({ force });
const url = `${t.apiBase}/v3/company/${t.realmId}/${path}${path.includes("?") ? "&" : "?"}minorversion=75`;
const r = await this.d.fetchFn(url, { method: "GET", headers: { Authorization: "Bearer " + t.accessToken, Accept: "application/json" } });
const tid = intuitTid(r);
if (r.ok) return r.json();
this.d.log?.("ошибка API QuickBooks", { status: r.status, path: path.split("?")[0], intuit_tid: tid, attempt });
if (r.status === 401 && !force) { force = true; continue; }
if (r.status === 429 || r.status >= 500) { await sleep(2000 * (attempt + 1)); continue; }
throw new Error(`QuickBooks ${r.status} на ${path.split("?")[0]}`);
throw new Error(`QuickBooks ${r.status} на ${path.split("?")[0]}${tid ? ` intuit_tid=${tid}` : ""}`);
}
throw new Error(`QuickBooks: не удалось выполнить ${path.split("?")[0]} за 5 попыток`);
}