Skip to content

Commit 0804496

Browse files
committed
Update Bouncers.tsx
1 parent 8d54909 commit 0804496

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

web/src/pages/Bouncers.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,30 @@ import { toast } from 'sonner'
3838
import { EmptyState, PageHeader, QueryError, ResultsSummary } from '@/components/common'
3939
import { useUrlFilters } from '@/hooks'
4040

41+
/**
42+
* Type guard to check if an object is a valid Bouncer.
43+
* This provides runtime validation of the data received from the API.
44+
*/
45+
function isBouncer(obj: unknown): obj is Bouncer {
46+
return (
47+
obj !== null &&
48+
typeof obj === 'object' &&
49+
'name' in obj &&
50+
typeof (obj as { name: unknown }).name === 'string' &&
51+
'ip_address' in obj &&
52+
typeof (obj as { ip_address: unknown }).ip_address === 'string' &&
53+
'valid' in obj &&
54+
typeof (obj as { valid: unknown }).valid === 'boolean'
55+
)
56+
}
57+
4158
function normalizeBouncers(raw: unknown): Bouncer[] {
42-
if (Array.isArray(raw)) return raw as Bouncer[]
59+
if (Array.isArray(raw)) {
60+
return raw.filter(isBouncer)
61+
}
4362

4463
if (raw && typeof raw === 'object' && 'bouncers' in raw && Array.isArray((raw as { bouncers: unknown }).bouncers)) {
45-
return (raw as { bouncers: Bouncer[] }).bouncers
64+
return (raw as { bouncers: unknown[] }).bouncers.filter(isBouncer)
4665
}
4766

4867
return []

0 commit comments

Comments
 (0)