An ATproto social media client -- with an independent Appview.
1import {t} from '@lingui/macro'
2
3export function cleanError(str: any): string {
4 if (!str) {
5 return ''
6 }
7 if (typeof str !== 'string') {
8 str = str.toString()
9 }
10 if (isNetworkError(str)) {
11 return t`Unable to connect. Please check your internet connection and try again.`
12 }
13 if (
14 str.includes('Upstream Failure') ||
15 str.includes('NotEnoughResources') ||
16 str.includes('pipethrough network error')
17 ) {
18 return t`The server appears to be experiencing issues. Please try again in a few moments.`
19 }
20 if (str.includes('Bad token scope') || str.includes('Bad token method')) {
21 return t`This feature is not available while using an App Password. Please sign in with your main password.`
22 }
23 if (str.startsWith('Error: ')) {
24 return str.slice('Error: '.length)
25 }
26 return str
27}
28
29const NETWORK_ERRORS = [
30 'Abort',
31 'Network request failed',
32 'Failed to fetch',
33 'Load failed',
34]
35
36export function isNetworkError(e: unknown) {
37 const str = String(e)
38 for (const err of NETWORK_ERRORS) {
39 if (str.includes(err)) {
40 return true
41 }
42 }
43 return false
44}