g1t/apps/sudo/app/lib/settle.ts
| 1 | /** |
| 2 | * A call whose failure should not take the whole page down: the page |
| 3 | * shows what it has and says what did not answer. No Workers imports. |
| 4 | */ |
| 5 | export type Settled<T> = { ok: true; value: T } | { ok: false; error: string }; |
| 6 | |
| 7 | export async function settle<T>(promise: Promise<T>): Promise<Settled<T>> { |
| 8 | try { |
| 9 | return { ok: true, value: await promise }; |
| 10 | } catch (error) { |
| 11 | return { ok: false, error: error instanceof Error ? error.message : String(error) }; |
| 12 | } |
| 13 | } |