Don't suggest retrying an unretryable error (#11159)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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`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)}
|
||||
/>
|
||||
) : (
|
||||
@@ -539,7 +547,11 @@ let SearchScreenUserResults = ({
|
||||
if (error) {
|
||||
return (
|
||||
<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()}
|
||||
/>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user