diff options
author | Eric Bailey <git@esb.lol> | 2025-05-27 13:25:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-27 13:25:41 -0500 |
commit | 342f820ec01fac0ff914175575bc7afe64fa71fd (patch) | |
tree | 6000b1192701409a53195ee12178aa0305759d95 /src/state/geolocation.tsx | |
parent | df2f62e94ddee0b13ae48859617473f1905ec792 (diff) | |
download | voidsky-342f820ec01fac0ff914175575bc7afe64fa71fd.tar.zst |
Quiet some logs, fix a bug (#8404)
* Composer, 142k * Log geolocation error at most once per session * Clean thumb cache, 1.4m * Quiet generic network errors * Handle undefined notification payloads
Diffstat (limited to 'src/state/geolocation.tsx')
-rw-r--r-- | src/state/geolocation.tsx | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/state/geolocation.tsx b/src/state/geolocation.tsx index 09b1b9471..83a42f21d 100644 --- a/src/state/geolocation.tsx +++ b/src/state/geolocation.tsx @@ -48,7 +48,7 @@ async function getGeolocation(): Promise<Device['geolocation']> { /** * Local promise used within this file only. */ -let geolocationResolution: Promise<void> | undefined +let geolocationResolution: Promise<{success: boolean}> | undefined /** * Begin the process of resolving geolocation. This should be called once at @@ -65,12 +65,14 @@ export function beginResolveGeolocation() { * and fail closed. */ if (__DEV__) { - geolocationResolution = new Promise(y => y()) + geolocationResolution = new Promise(y => y({success: true})) device.set(['geolocation'], DEFAULT_GEOLOCATION) return } geolocationResolution = new Promise(async resolve => { + let success = true + try { // Try once, fail fast const geolocation = await getGeolocation() @@ -83,7 +85,9 @@ export function beginResolveGeolocation() { throw new Error(`geolocation: nothing returned from initial request`) } } catch (e: any) { - logger.error(`geolocation: failed initial request`, { + success = false + + logger.debug(`geolocation: failed initial request`, { safeMessage: e.message, }) @@ -97,6 +101,7 @@ export function beginResolveGeolocation() { device.set(['geolocation'], geolocation) emitGeolocationUpdate(geolocation) logger.debug(`geolocation: success`, {geolocation}) + success = true } else { // endpoint should throw on all failures, this is insurance throw new Error(`geolocation: nothing returned from retries`) @@ -107,7 +112,7 @@ export function beginResolveGeolocation() { logger.debug(`geolocation: failed retries`, {safeMessage: e.message}) }) } finally { - resolve(undefined) + resolve({success}) } }) } @@ -127,10 +132,14 @@ export async function ensureGeolocationResolved() { logger.debug(`geolocation: using cache`, {cached}) } else { logger.debug(`geolocation: no cache`) - await geolocationResolution - logger.debug(`geolocation: resolved`, { - resolved: device.get(['geolocation']), - }) + const {success} = await geolocationResolution + if (success) { + logger.debug(`geolocation: resolved`, { + resolved: device.get(['geolocation']), + }) + } else { + logger.error(`geolocation: failed to resolve`) + } } } |