mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1export function cleanError(str: any): string {
2 if (!str) {
3 return ''
4 }
5 if (typeof str !== 'string') {
6 str = str.toString()
7 }
8 if (isNetworkError(str)) {
9 return 'Unable to connect. Please check your internet connection and try again.'
10 }
11 if (str.includes('Upstream Failure')) {
12 return 'The server appears to be experiencing issues. Please try again in a few moments.'
13 }
14 if (str.includes('Bad token scope')) {
15 return 'This feature is not available while using an App Password. Please sign in with your main password.'
16 }
17 if (str.startsWith('Error: ')) {
18 return str.slice('Error: '.length)
19 }
20 return str
21}
22
23const NETWORK_ERRORS = [
24 'Abort',
25 'Network request failed',
26 'Failed to fetch',
27 'Load failed',
28]
29
30export function isNetworkError(e: unknown) {
31 const str = String(e)
32 for (const err of NETWORK_ERRORS) {
33 if (str.includes(err)) {
34 return true
35 }
36 }
37 return false
38}