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.startsWith('Error: ')) { 15 return str.slice('Error: '.length) 16 } 17 return str 18} 19 20export function isNetworkError(e: unknown) { 21 const str = String(e) 22 return ( 23 str.includes('Abort') || 24 str.includes('Network request failed') || 25 str.includes('Failed to fetch') 26 ) 27}