From c73e3f904b8a55fa19a091e3aa9526b0945412e8 Mon Sep 17 00:00:00 2001 From: pqhuy1987 Date: Tue, 21 Apr 2026 15:46:04 +0700 Subject: [PATCH] =?UTF-8?q?[CLAUDE]=20FE:=20login=20error=20message=20h?= =?UTF-8?q?=C6=B0=E1=BB=9Bng=20d=E1=BA=ABn=20diagnose=20khi=20Network=20Er?= =?UTF-8?q?ror?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fe-admin/src/pages/LoginPage.tsx | 16 ++++++++++++---- fe-user/src/pages/LoginPage.tsx | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/fe-admin/src/pages/LoginPage.tsx b/fe-admin/src/pages/LoginPage.tsx index a37c14d..6097c23 100644 --- a/fe-admin/src/pages/LoginPage.tsx +++ b/fe-admin/src/pages/LoginPage.tsx @@ -24,10 +24,18 @@ export function LoginPage() { navigate(redirectTo, { replace: true }) toast.success('Đăng nhập thành công') } catch (err) { - const msg = axios.isAxiosError(err) - ? err.response?.data?.detail ?? err.response?.data?.title ?? err.message - : 'Lỗi kết nối máy chủ' - toast.error(`Đăng nhập thất bại: ${msg}`) + let msg: string + if (axios.isAxiosError(err)) { + if (err.code === 'ERR_NETWORK' || err.message === 'Network Error') { + const apiUrl = (import.meta.env.VITE_API_BASE_URL ?? window.location.origin) + '/api' + msg = `Không thể kết nối ${apiUrl}. Check dev tools F12 → Network. Có thể do cache cũ — thử Ctrl+Shift+R hoặc tab ẩn danh.` + } else { + msg = err.response?.data?.detail ?? err.response?.data?.title ?? err.message + } + } else { + msg = 'Lỗi không xác định' + } + toast.error(`Đăng nhập thất bại: ${msg}`, { duration: 8000 }) } finally { setIsSubmitting(false) } diff --git a/fe-user/src/pages/LoginPage.tsx b/fe-user/src/pages/LoginPage.tsx index 686e368..2a44c32 100644 --- a/fe-user/src/pages/LoginPage.tsx +++ b/fe-user/src/pages/LoginPage.tsx @@ -24,10 +24,18 @@ export function LoginPage() { navigate(redirectTo, { replace: true }) toast.success('Đăng nhập thành công') } catch (err) { - const msg = axios.isAxiosError(err) - ? err.response?.data?.detail ?? err.response?.data?.title ?? err.message - : 'Lỗi kết nối máy chủ' - toast.error(`Đăng nhập thất bại: ${msg}`) + let msg: string + if (axios.isAxiosError(err)) { + if (err.code === 'ERR_NETWORK' || err.message === 'Network Error') { + const apiUrl = (import.meta.env.VITE_API_BASE_URL ?? window.location.origin) + '/api' + msg = `Không thể kết nối ${apiUrl}. Check dev tools F12 → Network. Có thể do cache cũ — thử Ctrl+Shift+R hoặc tab ẩn danh.` + } else { + msg = err.response?.data?.detail ?? err.response?.data?.title ?? err.message + } + } else { + msg = 'Lỗi không xác định' + } + toast.error(`Đăng nhập thất bại: ${msg}`, { duration: 8000 }) } finally { setIsSubmitting(false) }