Don't suggest retrying an unretryable error (#11159)

This commit is contained in:
DS Boyce
2026-07-15 11:27:19 -07:00
committed by GitHub
parent 7009417035
commit a0c75944a3
3 changed files with 25 additions and 19 deletions
-11
View File
@@ -866,17 +866,6 @@
"count": 1 "count": 1
} }
}, },
"src/lib/strings/errors.ts": {
"typescript/no-explicit-any": {
"count": 1
},
"typescript/no-unsafe-call": {
"count": 14
},
"typescript/no-unsafe-member-access": {
"count": 14
}
},
"src/lib/useGetEmojis/getEmojis.ts": { "src/lib/useGetEmojis/getEmojis.ts": {
"typescript/require-await": { "typescript/require-await": {
"count": 1 "count": 1
+10 -5
View File
@@ -1,13 +1,12 @@
import {XRPCError} from '@atproto/api' import {XRPCError} from '@atproto/api'
import {t} from '@lingui/core/macro' import {t} from '@lingui/core/macro'
export function cleanError(str: any): string { export function cleanError(e: unknown): string {
if (!str) { if (!e) {
return '' return ''
} }
if (typeof str !== 'string') { // oxlint-disable-next-line typescript/no-base-to-string
str = str.toString() const str = typeof e === 'string' ? e : e.toString()
}
if (isNetworkError(str)) { if (isNetworkError(str)) {
return t`Unable to connect. Please check your internet connection and try again.` return t`Unable to connect. Please check your internet connection and try again.`
} }
@@ -86,3 +85,9 @@ export function isCancelledError(e: unknown) {
const str = String(e).toLowerCase() const str = String(e).toLowerCase()
return str.includes('cancel') return str.includes('cancel')
} }
// TODO Replace this with error.shouldRetry() when available. -dsb
const RETRYABLE_ERRORS = [408, 425, 429, 500, 502, 503, 504, 522, 524]
export function shouldRetryError(e: unknown) {
return e instanceof XRPCError && RETRYABLE_ERRORS.includes(e.status)
}
+15 -3
View File
@@ -6,7 +6,11 @@ import {Trans, useLingui} from '@lingui/react/macro'
import {urls} from '#/lib/constants' import {urls} from '#/lib/constants'
import {usePostViewTracking} from '#/lib/hooks/usePostViewTracking' import {usePostViewTracking} from '#/lib/hooks/usePostViewTracking'
import {useCallOnce} from '#/lib/once' import {useCallOnce} from '#/lib/once'
import {cleanError} from '#/lib/strings/errors' import {
cleanError,
isNetworkError,
shouldRetryError,
} from '#/lib/strings/errors'
import {augmentSearchQuery} from '#/lib/strings/helpers' import {augmentSearchQuery} from '#/lib/strings/helpers'
import {useActorSearch} from '#/state/queries/actor-search' import {useActorSearch} from '#/state/queries/actor-search'
import {usePopularFeedsSearch} from '#/state/queries/feed' import {usePopularFeedsSearch} from '#/state/queries/feed'
@@ -402,7 +406,11 @@ let SearchScreenPostResults = ({
return error ? ( return error ? (
<EmptyState <EmptyState
messageText={l`We’re sorry, but your search could not be completed. Please try again in a few minutes.`} messageText={
shouldRetryError(error) || isNetworkError(error)
? l`We’re sorry, but your search could not be completed. Please try again in a few minutes.`
: l`We’re sorry, but your search could not be completed.`
}
error={cleanError(error)} error={cleanError(error)}
/> />
) : ( ) : (
@@ -539,7 +547,11 @@ let SearchScreenUserResults = ({
if (error) { if (error) {
return ( return (
<EmptyState <EmptyState
messageText={l`We’re sorry, but your search could not be completed. Please try again in a few minutes.`} messageText={
shouldRetryError(error) || isNetworkError(error)
? l`We’re sorry, but your search could not be completed. Please try again in a few minutes.`
: l`We’re sorry, but your search could not be completed.`
}
error={error.toString()} error={error.toString()}
/> />
) )