Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫
Something went wrong. Try again.
673 B · 23 lines
TypeScript
at main
123456789101112131415161718192021222324import {emitNetworkConfirmed, emitNetworkLost} from '#/state/events'
/* * Captured once at module load so the wrapper below is immune to later * monkey-patching of globalThis.fetch. */const realFetch = globalThis.fetch
/** * Fetch wrapper that reports network reachability to the app-wide event bus. * Any resolved response (including HTTP errors) confirms the network is up; a * thrown error (DNS failure, timeout, offline) reports it as lost. */export const networkAwareFetch: typeof fetch = async (...args) => { try { const res = await realFetch(...args) emitNetworkConfirmed() return res } catch (e) { emitNetworkLost() throw e }}