Skip to content

Commit bea8e26

Browse files
fix[frontend](broadcast): removed null arrays access with .length
1 parent d5e7392 commit bea8e26

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

frontend/src/features/platform-broadcast/services/broadcast-http.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ function withSelector<T extends object>(selector: BulkSelector, resource: T) {
3232
return { selector, ...resource }
3333
}
3434

35+
// Go's nil slices marshal to JSON null; normalize so consumers can safely read `.length`.
36+
function normalize(r: BulkResult | null | undefined): BulkResult {
37+
return { succeeded: r?.succeeded ?? [], failed: r?.failed ?? [] }
38+
}
39+
3540
async function post<Resource extends object>(
3641
path: string,
3742
selector: BulkSelector,
3843
resource: Resource,
3944
): Promise<BulkResult> {
40-
return api.post<BulkResult>(path, withSelector(selector, resource))
45+
return normalize(await api.post<BulkResult>(path, withSelector(selector, resource)))
4146
}
4247

4348
/** Send `resource` to every selected tenant against `path` (a full `/platform/**\/bulk/**` route). */
@@ -108,5 +113,5 @@ export async function broadcastBrandingAsset(
108113
const form = new FormData()
109114
form.append('file', file)
110115
form.append('selector', JSON.stringify(selector))
111-
return api.post<BulkResult>(BULK_PATHS.branding.uploadAsset(slot), form)
116+
return normalize(await api.post<BulkResult>(BULK_PATHS.branding.uploadAsset(slot), form))
112117
}

0 commit comments

Comments
 (0)