fix: no attachment broadcast fix
This commit is contained in:
+8
-2
@@ -18,8 +18,14 @@ async function call<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
});
|
||||
if (!res.ok) throw new Error(`broadcast request failed: ${res.status}`);
|
||||
if (res.status === 204) return undefined as T;
|
||||
const json = await res.json();
|
||||
return (json?.data ?? json) as T;
|
||||
const body = (await res.json().catch(() => ({}))) as {
|
||||
data?: T;
|
||||
success?: boolean;
|
||||
};
|
||||
// NOT `body.data ?? body`: /pending answers {data: null} when nothing is
|
||||
// waiting, and `??` would fall through and hand back the whole envelope —
|
||||
// which is truthy, so the modal would try to render it as an announcement.
|
||||
return (body.data ?? (null as unknown as T)) as T;
|
||||
}
|
||||
|
||||
export type Broadcast = {
|
||||
|
||||
Reference in New Issue
Block a user