Fix retries in threadgate too, add comments
This commit is contained in:
@@ -35,10 +35,14 @@ export async function getPostgateRecord({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO don't retry on 404
|
|
||||||
const {data} = await retry(
|
const {data} = await retry(
|
||||||
2,
|
2,
|
||||||
e => {
|
e => {
|
||||||
|
/*
|
||||||
|
* If the record doesn't exist, we want to return null instead of
|
||||||
|
* throwing an error. NB: This will also catch reference errors, such as
|
||||||
|
* a typo in the URI.
|
||||||
|
*/
|
||||||
if (e.message.includes(`Could not locate record:`)) {
|
if (e.message.includes(`Could not locate record:`)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -58,6 +62,11 @@ export async function getPostgateRecord({
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
/*
|
||||||
|
* If the record doesn't exist, we want to return null instead of
|
||||||
|
* throwing an error. NB: This will also catch reference errors, such as
|
||||||
|
* a typo in the URI.
|
||||||
|
*/
|
||||||
if (e.message.includes(`Could not locate record:`)) {
|
if (e.message.includes(`Could not locate record:`)) {
|
||||||
return undefined
|
return undefined
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {AppBskyFeedThreadgate, AtUri, BskyAgent} from '@atproto/api'
|
import {AppBskyFeedThreadgate, AtUri, BskyAgent} from '@atproto/api'
|
||||||
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {networkRetry} from '#/lib/async/retry'
|
import {networkRetry, retry} from '#/lib/async/retry'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types'
|
import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types'
|
||||||
import {
|
import {
|
||||||
@@ -60,12 +60,25 @@ export async function getThreadgateRecord({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {data} = await networkRetry(2, () =>
|
const {data} = await retry(
|
||||||
agent.api.com.atproto.repo.getRecord({
|
2,
|
||||||
repo: urip.host,
|
e => {
|
||||||
collection: 'app.bsky.feed.threadgate',
|
/*
|
||||||
rkey: urip.rkey,
|
* If the record doesn't exist, we want to return null instead of
|
||||||
}),
|
* throwing an error. NB: This will also catch reference errors, such as
|
||||||
|
* a typo in the URI.
|
||||||
|
*/
|
||||||
|
if (e.message.includes(`Could not locate record:`)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
() =>
|
||||||
|
agent.api.com.atproto.repo.getRecord({
|
||||||
|
repo: urip.host,
|
||||||
|
collection: 'app.bsky.feed.threadgate',
|
||||||
|
rkey: urip.rkey,
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (data.value && AppBskyFeedThreadgate.isRecord(data.value)) {
|
if (data.value && AppBskyFeedThreadgate.isRecord(data.value)) {
|
||||||
@@ -74,6 +87,11 @@ export async function getThreadgateRecord({
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
/*
|
||||||
|
* If the record doesn't exist, we want to return null instead of
|
||||||
|
* throwing an error. NB: This will also catch reference errors, such as
|
||||||
|
* a typo in the URI.
|
||||||
|
*/
|
||||||
if (e.message.includes(`Could not locate record:`)) {
|
if (e.message.includes(`Could not locate record:`)) {
|
||||||
return null
|
return null
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user