Skip to content

Commit c582e09

Browse files
committed
fix(connectors): inspect all drive error reasons
1 parent de451bf commit c582e09

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

apps/sim/connectors/google-drive/google-drive-errors.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,22 @@ function classifyGoogleDriveError(
9898

9999
export class GoogleDriveApiError extends Error {
100100
retryAfterMs?: number
101+
readonly reasons: readonly string[]
102+
readonly kind: GoogleDriveErrorKind
101103
readonly rateLimited: boolean
102104

103105
constructor(
104106
readonly status: number,
105-
readonly reasons: readonly string[],
106-
readonly kind: GoogleDriveErrorKind
107+
normalizedReasons: readonly string[]
107108
) {
108-
const reasonSuffix = reasons.length > 0 ? ` (${reasons.join(', ')})` : ''
109+
const diagnosticReasons = normalizedReasons.slice(0, GOOGLE_ERROR_REASON_MAX_COUNT)
110+
const reasonSuffix = diagnosticReasons.length > 0 ? ` (${diagnosticReasons.join(', ')})` : ''
109111
super(`Google Drive API request failed with HTTP ${status}${reasonSuffix}`)
110112
this.name = 'GoogleDriveApiError'
111-
this.rateLimited = status === 429 || reasons.some((reason) => RATE_LIMIT_REASONS.has(reason))
113+
this.reasons = diagnosticReasons
114+
this.kind = classifyGoogleDriveError(status, normalizedReasons)
115+
this.rateLimited =
116+
status === 429 || normalizedReasons.some((reason) => RATE_LIMIT_REASONS.has(reason))
112117
}
113118
}
114119

@@ -131,13 +136,8 @@ export async function readGoogleDriveApiError(response: Response): Promise<Googl
131136

132137
const entries = parsedBody?.error?.errors ?? []
133138
const rawReasons = [...new Set(entries.flatMap((entry) => (entry.reason ? [entry.reason] : [])))]
134-
const reasons = [...new Set(rawReasons.flatMap((reason) => normalizeReason(reason) ?? []))].slice(
135-
0,
136-
GOOGLE_ERROR_REASON_MAX_COUNT
137-
)
138-
return new GoogleDriveApiError(
139-
response.status,
140-
reasons,
141-
classifyGoogleDriveError(response.status, rawReasons)
142-
)
139+
const normalizedReasons = [
140+
...new Set(rawReasons.flatMap((reason) => normalizeReason(reason) ?? [])),
141+
]
142+
return new GoogleDriveApiError(response.status, normalizedReasons)
143143
}

apps/sim/connectors/google-drive/google-drive.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ describe('Google Drive API error parsing', () => {
106106
expect(backendFailure.rateLimited).toBe(false)
107107
})
108108

109+
it('detects a structured rate limit beyond the bounded diagnostic reasons', async () => {
110+
const reasons = [
111+
...Array.from({ length: 16 }, (_, index) => `providerReason${index}`),
112+
'userRateLimitExceeded',
113+
]
114+
const error = await readGoogleDriveApiError(
115+
jsonResponse(
116+
{
117+
error: {
118+
errors: reasons.map((reason) => ({ reason })),
119+
},
120+
},
121+
403
122+
)
123+
)
124+
125+
expect(error.reasons).toEqual(reasons.slice(0, 16))
126+
expect(error.kind).toBe('transient')
127+
expect(error.rateLimited).toBe(true)
128+
})
129+
109130
it('omits provider messages from diagnostics', async () => {
110131
const message = `Authorization: Bearer private-token\ncontext ${'x'.repeat(700)}`
111132
const error = await readGoogleDriveApiError(

0 commit comments

Comments
 (0)