Fix server state query returning undefined (#10232)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -183,7 +183,7 @@ export async function getServerState({agent}: {agent: AtpAgent}) {
|
|||||||
const geolocation = device.get(['mergedGeolocation'])
|
const geolocation = device.get(['mergedGeolocation'])
|
||||||
if (!geolocation || !geolocation.countryCode) {
|
if (!geolocation || !geolocation.countryCode) {
|
||||||
logger.error(`getServerState: missing geolocation countryCode`)
|
logger.error(`getServerState: missing geolocation countryCode`)
|
||||||
return
|
return null
|
||||||
}
|
}
|
||||||
const {data} = await agent.app.bsky.ageassurance.getState({
|
const {data} = await agent.app.bsky.ageassurance.getState({
|
||||||
countryCode: geolocation.countryCode,
|
countryCode: geolocation.countryCode,
|
||||||
@@ -225,7 +225,9 @@ export async function prefetchServerState({agent}: {agent: AtpAgent}) {
|
|||||||
try {
|
try {
|
||||||
logger.debug(`prefetchServerState: resolving...`)
|
logger.debug(`prefetchServerState: resolving...`)
|
||||||
const res = await networkRetry(3, () => getServerState({agent}))
|
const res = await networkRetry(3, () => getServerState({agent}))
|
||||||
qc.setQueryData<AppBskyAgeassuranceGetState.OutputSchema>(qk, res)
|
if (res) {
|
||||||
|
qc.setQueryData<AppBskyAgeassuranceGetState.OutputSchema>(qk, res)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const e = err as Error
|
const e = err as Error
|
||||||
logger.warn(`prefetchServerState: failed`, {
|
logger.warn(`prefetchServerState: failed`, {
|
||||||
@@ -238,10 +240,12 @@ export async function refetchServerState({agent}: {agent: AtpAgent}) {
|
|||||||
if (!did) return
|
if (!did) return
|
||||||
logger.debug(`refetchServerState: fetching...`)
|
logger.debug(`refetchServerState: fetching...`)
|
||||||
const res = await networkRetry(3, () => getServerState({agent}))
|
const res = await networkRetry(3, () => getServerState({agent}))
|
||||||
qc.setQueryData<AppBskyAgeassuranceGetState.OutputSchema>(
|
if (res) {
|
||||||
createServerStateQueryKey({did}),
|
qc.setQueryData<AppBskyAgeassuranceGetState.OutputSchema>(
|
||||||
res,
|
createServerStateQueryKey({did}),
|
||||||
)
|
res,
|
||||||
|
)
|
||||||
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
export function usePatchServerState() {
|
export function usePatchServerState() {
|
||||||
|
|||||||
Reference in New Issue
Block a user