Skip to content

Commit edec60b

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
refactor(quickbooks): use standard error payload handling
1 parent f4d89c6 commit edec60b

2 files changed

Lines changed: 5 additions & 54 deletions

File tree

apps/sim/tools/index.test.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,50 +2047,6 @@ describe('OAuth provider context propagation', () => {
20472047
})
20482048
expect(fetchMock).toHaveBeenCalledTimes(2)
20492049
})
2050-
2051-
it('does not expose a non-JSON QuickBooks failure body in tool output', async () => {
2052-
mockGenerateInternalToken.mockResolvedValue('internal-token')
2053-
const fetchMock = vi.fn().mockImplementation(async (url: string) => {
2054-
if (url.includes('/api/auth/oauth/token')) {
2055-
return new Response(
2056-
JSON.stringify({
2057-
accessToken: 'fresh-access-token',
2058-
realmId: '123456789',
2059-
}),
2060-
{ headers: { 'Content-Type': 'application/json' } }
2061-
)
2062-
}
2063-
2064-
return new Response('<html>sensitive gateway body</html>', {
2065-
status: 502,
2066-
statusText: 'Bad Gateway',
2067-
headers: { 'Content-Type': 'text/html' },
2068-
})
2069-
})
2070-
global.fetch = Object.assign(fetchMock, { preconnect: vi.fn() }) as typeof fetch
2071-
2072-
const result = await executeTool(
2073-
'test_quickbooks_context',
2074-
{ credential: 'quickbooks-credential' },
2075-
{
2076-
executionContext: createToolExecutionContext({
2077-
userId: 'user-123',
2078-
workflowId: 'workflow-123',
2079-
}),
2080-
}
2081-
)
2082-
2083-
expect(result).toMatchObject({
2084-
success: false,
2085-
error: 'QuickBooks request failed with HTTP 502.',
2086-
output: {
2087-
status: 502,
2088-
statusText: 'Bad Gateway',
2089-
data: null,
2090-
},
2091-
})
2092-
expect(JSON.stringify(result)).not.toContain('sensitive gateway body')
2093-
})
20942050
})
20952051

20962052
describe('Copilot Env Variable Reference Resolution', () => {

apps/sim/tools/index.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ import type { ExecutionContext, UserFile } from '@/executor/types'
4949
import { resolveEnvVarReferences } from '@/executor/utils/reference-validation'
5050
import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'
5151
import type { ErrorInfo } from '@/tools/error-extractors'
52-
import { ErrorExtractorId, extractErrorMessage } from '@/tools/error-extractors'
52+
import { extractErrorMessage } from '@/tools/error-extractors'
5353
import { HostedKeyRateLimitedError, HostedKeyUnavailableError } from '@/tools/errors'
54-
import { sanitizeQuickBooksFaultData } from '@/tools/quickbooks/fault'
5554
import type {
5655
BYOKProviderId,
5756
OAuthTokenPayload,
@@ -981,16 +980,12 @@ const MCP_SYSTEM_PARAMETERS = new Set([
981980
* Uses the error extractor registry to find the best error message
982981
*/
983982
function createTransformedErrorFromErrorInfo(errorInfo?: ErrorInfo, extractorId?: string): Error {
984-
const safeErrorInfo =
985-
extractorId === ErrorExtractorId.QUICKBOOKS_FAULT && errorInfo
986-
? { ...errorInfo, data: sanitizeQuickBooksFaultData(errorInfo.data) }
987-
: errorInfo
988-
const message = extractErrorMessage(safeErrorInfo, extractorId)
983+
const message = extractErrorMessage(errorInfo, extractorId)
989984
const transformed = new Error(message)
990985
Object.assign(transformed, {
991-
status: safeErrorInfo?.status,
992-
statusText: safeErrorInfo?.statusText,
993-
data: safeErrorInfo?.data,
986+
status: errorInfo?.status,
987+
statusText: errorInfo?.statusText,
988+
data: errorInfo?.data,
994989
})
995990
return transformed
996991
}

0 commit comments

Comments
 (0)