Retro Bulletin Board Systems on atproto. Web app and TUI. lazy mirror of alyraffauf/atbbs atbbs.xyz
forums python tui atproto bbs
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

web/lib: add assertOk

+16 -15
+3 -3
web/src/lib/atproto.ts
··· 35 35 } 36 36 37 37 async function fetchJson<T>(url: string): Promise<T> { 38 - const r = await fetch(url); 39 - if (!r.ok) throw new Error(`${r.status} ${url}`); 40 - return r.json() as Promise<T>; 38 + const resp = await fetch(url); 39 + if (!resp.ok) throw new Error(`${resp.status} ${url}`); 40 + return resp.json() as Promise<T>; 41 41 } 42 42 43 43 export async function resolveIdentity(identifier: string): Promise<MiniDoc> {
+13 -12
web/src/lib/writes.ts
··· 50 50 51 51 // --- Generic record CRUD --- 52 52 53 + function assertOk( 54 + resp: { ok: boolean; data: unknown }, 55 + label: string, 56 + ): asserts resp is { ok: true; data: unknown } { 57 + if (!resp.ok) { 58 + const message = (resp.data as { message?: string })?.message; 59 + throw new Error(message ?? `${label} failed`); 60 + } 61 + } 62 + 53 63 async function createRecord<V extends object>( 54 64 rpc: Client, 55 65 collection: string, ··· 64 74 record: { $type: collection, ...value }, 65 75 }, 66 76 }); 67 - if (!resp.ok) { 68 - const message = (resp.data as { message?: string })?.message; 69 - throw new Error(message ?? "createRecord failed"); 70 - } 77 + assertOk(resp, "createRecord"); 71 78 return resp; 72 79 } 73 80 ··· 85 92 record: { $type: collection, ...value }, 86 93 }, 87 94 }); 88 - if (!resp.ok) { 89 - const message = (resp.data as { message?: string })?.message; 90 - throw new Error(message ?? "putRecord failed"); 91 - } 95 + assertOk(resp, "putRecord"); 92 96 return resp; 93 97 } 94 98 ··· 104 108 rkey, 105 109 }, 106 110 }); 107 - if (!resp.ok) { 108 - const message = (resp.data as { message?: string })?.message; 109 - throw new Error(message ?? "deleteRecord failed"); 110 - } 111 + assertOk(resp, "deleteRecord"); 111 112 return resp; 112 113 } 113 114