diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json index b5eb42488b..f846bb0561 100644 --- a/oxlint-suppressions.json +++ b/oxlint-suppressions.json @@ -866,17 +866,6 @@ "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": { "typescript/require-await": { "count": 1 diff --git a/src/lib/strings/errors.ts b/src/lib/strings/errors.ts index 5f56cccc4d..994c91515b 100644 --- a/src/lib/strings/errors.ts +++ b/src/lib/strings/errors.ts @@ -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) +} diff --git a/src/screens/Search/SearchResults.tsx b/src/screens/Search/SearchResults.tsx index 8d1377be33..70755e8148 100644 --- a/src/screens/Search/SearchResults.tsx +++ b/src/screens/Search/SearchResults.tsx @@ -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 ? ( ) : ( @@ -539,7 +547,11 @@ let SearchScreenUserResults = ({ if (error) { return ( )