kaneo (minimalist kanban) fork to experiment adding a tangled integration github.com/usekaneo/kaneo
at main 93 lines 2.5 kB view raw
1export type ApiError = { 2 message: string; 3 type: "network" | "cors" | "auth" | "server" | "unknown"; 4 status?: number; 5 originalError?: Error; 6}; 7 8export function parseApiError(error: unknown): ApiError { 9 if (error instanceof Error) { 10 if ( 11 error.message.includes("Failed to fetch") || 12 error.message.includes("NetworkError") || 13 error.message.includes("CORS") 14 ) { 15 return { 16 message: 17 "Unable to connect to the server. This might be due to CORS configuration issues.", 18 type: "cors", 19 originalError: error, 20 }; 21 } 22 23 if ( 24 error.message.includes("fetch") || 25 error.message.includes("network") || 26 error.message.includes("connection") 27 ) { 28 return { 29 message: 30 "Network error. Please check your internet connection and try again.", 31 type: "network", 32 originalError: error, 33 }; 34 } 35 36 if ( 37 error.message.includes("401") || 38 error.message.includes("unauthorized") || 39 error.message.includes("authentication") 40 ) { 41 return { 42 message: "Authentication failed. Please sign in again.", 43 type: "auth", 44 status: 401, 45 originalError: error, 46 }; 47 } 48 49 // Check for server errors 50 if ( 51 error.message.includes("500") || 52 error.message.includes("server error") || 53 error.message.includes("internal") 54 ) { 55 return { 56 message: "Server error. Please try again later.", 57 type: "server", 58 status: 500, 59 originalError: error, 60 }; 61 } 62 63 return { 64 message: error.message || "An unexpected error occurred.", 65 type: "unknown", 66 originalError: error, 67 }; 68 } 69 70 return { 71 message: "An unexpected error occurred.", 72 type: "unknown", 73 }; 74} 75 76export function getCorsTroubleshootingSteps(): string[] { 77 return [ 78 "Make sure your API server is running", 79 "Check that VITE_API_URL in your frontend .env matches your API server URL", 80 "Verify CORS_ORIGINS in your API .env includes your frontend URL", 81 "Ensure both frontend and API are using the same protocol (http/https)", 82 "Check that your API server is accessible from your browser", 83 ]; 84} 85 86export function getNetworkTroubleshootingSteps(): string[] { 87 return [ 88 "Check your internet connection", 89 "Verify the API server is running and accessible", 90 "Try refreshing the page", 91 "Check if there are any firewall or proxy issues", 92 ]; 93}