Skip to content

Commit 8248103

Browse files
fix(wiza): only accept trimmed string messages in error extractor
1 parent 56f5b0b commit 8248103

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎apps/sim/tools/error-extractors.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,14 @@ describe('Error Extractors', () => {
388388
expect(extractErrorMessage(errorInfo, ErrorExtractorId.WIZA_ERRORS)).toBe('Bad gateway')
389389
})
390390

391+
it('ignores a non-string top-level message', () => {
392+
const errorInfo: ErrorInfo = { status: 422, data: { message: ['bad filter'] } }
393+
394+
expect(extractErrorMessage(errorInfo, ErrorExtractorId.WIZA_ERRORS)).toBe(
395+
'Request failed with status 422'
396+
)
397+
})
398+
391399
it('falls back to the status when Wiza sends an empty message', () => {
392400
const errorInfo: ErrorInfo = { status: 400, data: { status: { code: 400, message: '' } } }
393401

‎apps/sim/tools/error-extractors.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,11 @@ const ERROR_EXTRACTORS: ErrorExtractorConfig[] = [
521521
examples: ['Wiza'],
522522
extract: (errorInfo) => {
523523
const data = errorInfo?.data
524-
if (typeof data === 'string') return data.trim() || undefined
525-
const message = data?.status?.message
526-
if (typeof message === 'string' && message.trim()) return message.trim()
527-
return data?.message
524+
const candidates = [data, data?.status?.message, data?.message]
525+
for (const candidate of candidates) {
526+
if (typeof candidate === 'string' && candidate.trim()) return candidate.trim()
527+
}
528+
return undefined
528529
},
529530
},
530531
{

0 commit comments

Comments
 (0)