Ensure the UI always renders, even in bad network conditions (close #6)

This commit is contained in:
Paul Frazee 2022-12-05 13:25:04 -06:00
parent 59363181e1
commit f27e32e54c
13 changed files with 259 additions and 72 deletions

4
src/lib/errors.ts Normal file
View file

@ -0,0 +1,4 @@
export function isNetworkError(e: unknown) {
const str = String(e)
return str.includes('Aborted') || str.includes('Network request failed')
}

View file

@ -1,6 +1,7 @@
import {AtUri} from '../third-party/uri'
import {Entity} from '../third-party/api/src/client/types/app/bsky/feed/post'
import {PROD_SERVICE} from '../state'
import {isNetworkError} from './errors'
import TLDs from 'tlds'
export const MAX_DISPLAY_NAME = 64
@ -201,7 +202,7 @@ export function enforceLen(str: string, len: number): string {
}
export function cleanError(str: string): string {
if (str.includes('Network request failed')) {
if (isNetworkError(str)) {
return 'Unable to connect. Please check your internet connection and try again.'
}
if (str.startsWith('Error: ')) {