From 272f325d983fa0c23d8d38266f422643f978f675 Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Tue, 17 Feb 2026 13:13:05 -0600 Subject: [PATCH] sfsdf --- qbo_helper.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/qbo_helper.js b/qbo_helper.js index bb9940f..3e11bf6 100644 --- a/qbo_helper.js +++ b/qbo_helper.js @@ -1,4 +1,4 @@ -// qbo_helper.js - FINALE VERSION +// qbo_helper.js - FIX FÜR ERROR 3200 require('dotenv').config(); const OAuthClient = require('intuit-oauth'); const fs = require('fs'); @@ -19,7 +19,6 @@ const getOAuthClient = () => { let savedToken = null; try { if (fs.existsSync(tokenFile)) { - // Wir lesen nur, wenn es kein Ordner ist (für lokale Tests ohne Docker) const stat = fs.statSync(tokenFile); if (stat.isFile()) { const content = fs.readFileSync(tokenFile, 'utf8'); @@ -74,34 +73,37 @@ async function makeQboApiCall(requestOptions) { } }; - // --- WICHTIG: KEINE isAccessTokenValid() PRÜFUNG HIER! --- - // Wir vertrauen darauf, dass der Token (egal ob Datei oder .env) funktioniert. - // Wir refreshen nur, wenn QBO uns abweist. - try { const response = await client.makeApiCall(requestOptions); + // Prüfen, ob die Antwort JSON ist (manche Auth-Fehler sind HTML/Text) const data = response.getJson ? response.getJson() : response.json; if (data.fault && data.fault.error) { const errorCode = data.fault.error[0].code; - if (errorCode === '3202' || errorCode === '3100') { + + // --- FIX: 3200 (Auth Failed) HINZUGEFÜGT --- + if (errorCode === '3200' || errorCode === '3202' || errorCode === '3100') { console.log(`⚠️ QBO meldet Token-Fehler (${errorCode}). Versuche Refresh und Retry...`); await doRefresh(); + // Retry mit neuem Token return await client.makeApiCall(requestOptions); } throw new Error(`QBO API Error ${errorCode}: ${data.fault.error[0].message}`); } - // Bei Erfolg: Speichern (falls sich intern was geändert hat durch die Lib) saveTokens(); return response; } catch (e) { - const isAuthError = e.response?.status === 401 || (e.authResponse && e.authResponse.response && e.authResponse.response.status === 401); + // HTTP 401 Unauthorized fangen (falls die Lib wirft, statt data.fault zurückzugeben) + const isAuthError = + e.response?.status === 401 || + (e.authResponse && e.authResponse.response && e.authResponse.response.status === 401) || + e.message?.includes('AuthenticationFailed'); if (isAuthError) { - console.log("⚠️ 401 Unauthorized erhalten. Versuche Refresh und Retry..."); + console.log("⚠️ 401 Unauthorized / AuthFailed erhalten. Versuche Refresh und Retry..."); await doRefresh(); return await client.makeApiCall(requestOptions); }