qbo_auth: захват intuit_tid в логах и ошибках; документ требований Intuit (intuit_requirements.md)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 попыток`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user