error handling
This commit is contained in:
parent
a8b82783b1
commit
b5ac7f0807
21
server.js
21
server.js
|
|
@ -194,12 +194,18 @@ async function exportInvoiceToQbo(invoiceId, client) {
|
||||||
const data = response.getJson ? response.getJson() : response.json;
|
const data = response.getJson ? response.getJson() : response.json;
|
||||||
|
|
||||||
if (data.Fault?.Error?.[0]?.code === '6140') {
|
if (data.Fault?.Error?.[0]?.code === '6140') {
|
||||||
|
console.log(` ⚠️ DocNumber ${qboPayload.DocNumber} exists, retrying...`);
|
||||||
qboPayload.DocNumber = (parseInt(qboPayload.DocNumber) + 1).toString();
|
qboPayload.DocNumber = (parseInt(qboPayload.DocNumber) + 1).toString();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (data.Fault) {
|
||||||
|
const errMsg = data.Fault.Error?.map(e => `${e.code}: ${e.Message} - ${e.Detail}`).join('; ') || JSON.stringify(data.Fault);
|
||||||
|
console.error(`❌ QBO Export Fault:`, errMsg);
|
||||||
|
throw new Error('QBO export failed: ' + errMsg);
|
||||||
|
}
|
||||||
qboInvoice = data.Invoice || data;
|
qboInvoice = data.Invoice || data;
|
||||||
if (qboInvoice.Id) break;
|
if (qboInvoice.Id) break;
|
||||||
throw new Error("QBO returned no ID: " + (data.Fault?.Error?.[0]?.Message || JSON.stringify(data)));
|
throw new Error("QBO returned no ID: " + JSON.stringify(data).substring(0, 500));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!qboInvoice?.Id) throw new Error('Could not find free DocNumber after 5 attempts.');
|
if (!qboInvoice?.Id) throw new Error('Could not find free DocNumber after 5 attempts.');
|
||||||
|
|
@ -279,8 +285,19 @@ async function syncInvoiceToQbo(invoiceId, client) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateData = updateRes.getJson ? updateRes.getJson() : updateRes.json;
|
const updateData = updateRes.getJson ? updateRes.getJson() : updateRes.json;
|
||||||
|
|
||||||
|
// Prüfe auf Fault
|
||||||
|
if (updateData.Fault) {
|
||||||
|
const errMsg = updateData.Fault.Error?.map(e => `${e.code}: ${e.Message} - ${e.Detail}`).join('; ') || JSON.stringify(updateData.Fault);
|
||||||
|
console.error(`❌ QBO Sync Fault:`, errMsg);
|
||||||
|
throw new Error('QBO sync failed: ' + errMsg);
|
||||||
|
}
|
||||||
|
|
||||||
const updated = updateData.Invoice || updateData;
|
const updated = updateData.Invoice || updateData;
|
||||||
if (!updated.Id) throw new Error('QBO update returned no ID');
|
if (!updated.Id) {
|
||||||
|
console.error(`❌ QBO unexpected response:`, JSON.stringify(updateData).substring(0, 500));
|
||||||
|
throw new Error('QBO update returned no ID');
|
||||||
|
}
|
||||||
|
|
||||||
await client.query(
|
await client.query(
|
||||||
'UPDATE invoices SET qbo_sync_token = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2',
|
'UPDATE invoices SET qbo_sync_token = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue