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
23export function isNetworkError(e: unknown) {
24 const str = String(e)
25 return (
26 str.includes('Abort') ||
27 str.includes('Network request failed') ||
28 str.includes('Failed to fetch')
29 )
30}