Skip to content

Commit 970d3b1

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(quickbooks): handle non-json token errors
1 parent 25e5420 commit 970d3b1

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

apps/sim/lib/auth/auth.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3244,13 +3244,21 @@ export const auth = betterAuth({
32443244
}),
32453245
signal: AbortSignal.timeout(QUICKBOOKS_OAUTH_REQUEST_TIMEOUT_MS),
32463246
})
3247+
if (!response.ok) {
3248+
await readResponseTextWithLimit(response, {
3249+
maxBytes: DEFAULT_MAX_ERROR_BODY_BYTES,
3250+
label: 'QuickBooks OAuth token error response',
3251+
}).catch(() => {})
3252+
throw new Error(`QuickBooks OAuth token exchange failed with HTTP ${response.status}`)
3253+
}
3254+
32473255
const data = await readResponseJsonWithLimit<Record<string, unknown>>(response, {
32483256
maxBytes: DEFAULT_MAX_ERROR_BODY_BYTES,
32493257
label: 'QuickBooks OAuth token response',
32503258
})
32513259

3252-
if (!response.ok || !data || typeof data !== 'object' || Array.isArray(data)) {
3253-
throw new Error(`QuickBooks OAuth token exchange failed with HTTP ${response.status}`)
3260+
if (!data || typeof data !== 'object' || Array.isArray(data)) {
3261+
throw new Error('QuickBooks OAuth token exchange returned an invalid response')
32543262
}
32553263

32563264
const tokens = getOAuth2Tokens(data)

0 commit comments

Comments
 (0)