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
+10 -5
View File
@@ -1,13 +1,12 @@
import {XRPCError} from '@atproto/api'
import {t} from '@lingui/core/macro'
export function cleanError(str: any): string {
if (!str) {
export function cleanError(e: unknown): string {
if (!e) {
return ''
}
if (typeof str !== 'string') {
str = str.toString()
}
// oxlint-disable-next-line typescript/no-base-to-string
const str = typeof e === 'string' ? e : e.toString()
if (isNetworkError(str)) {
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()
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 {usePostViewTracking} from '#/lib/hooks/usePostViewTracking'
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 {useActorSearch} from '#/state/queries/actor-search'
import {usePopularFeedsSearch} from '#/state/queries/feed'
@@ -402,7 +406,11 @@ let SearchScreenPostResults = ({
return error ? (
<EmptyState
messageText={l`Were sorry, but your search could not be completed. Please try again in a few minutes.`}
messageText={
shouldRetryError(error) || isNetworkError(error)
? l`Were sorry, but your search could not be completed. Please try again in a few minutes.`
: l`Were sorry, but your search could not be completed.`
}
error={cleanError(error)}
/>
) : (
@@ -539,7 +547,11 @@ let SearchScreenUserResults = ({
if (error) {
return (
<EmptyState
messageText={l`Were sorry, but your search could not be completed. Please try again in a few minutes.`}
messageText={
shouldRetryError(error) || isNetworkError(error)
? l`Were sorry, but your search could not be completed. Please try again in a few minutes.`
: l`Were sorry, but your search could not be completed.`
}
error={error.toString()}
/>
)