From f31a5198bab67ac309bf2cf30761a8dcf1bcf1a5 Mon Sep 17 00:00:00 2001 From: "ruiyi.jiang" Date: Tue, 8 Aug 2023 09:48:57 +0800 Subject: [PATCH] error handle for database Signed-off-by: ruiyi.jiang --- client/src/context/Data.tsx | 8 ++++++-- client/src/pages/database/Database.tsx | 14 ++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/client/src/context/Data.tsx b/client/src/context/Data.tsx index 3a5e8d00..7923b9af 100644 --- a/client/src/context/Data.tsx +++ b/client/src/context/Data.tsx @@ -15,8 +15,12 @@ export const DataProvider = (props: { children: React.ReactNode }) => { const [databases, setDatabases] = useState(['default']); const fetchDatabases = async () => { - const res = await DatabaseHttp.getDatabases(); - setDatabases(res.db_names); + try { + const res = await DatabaseHttp.getDatabases(); + setDatabases(res.db_names); + } catch (error) { + // do nothing + } }; useEffect(() => { diff --git a/client/src/pages/database/Database.tsx b/client/src/pages/database/Database.tsx index 25035625..eb0aa2b5 100644 --- a/client/src/pages/database/Database.tsx +++ b/client/src/pages/database/Database.tsx @@ -18,7 +18,9 @@ const Database = () => { useNavigationHook(ALL_ROUTER_TYPES.DATABASES); const { setDatabaseList } = useContext(dataContext); - const [databases, setDatabases] = useState([]); + const [databases, setDatabases] = useState([ + { name: 'default' }, + ]); const [selectedDatabase, setSelectedDatabase] = useState([]); const { setDialog, handleCloseDialog, openSnackBar } = useContext(rootContext); @@ -28,9 +30,13 @@ const Database = () => { const { t: dialogTrans } = useTranslation('dialog'); const fetchDatabases = async () => { - const res = await DatabaseHttp.getDatabases(); - setDatabases(res.db_names.map((v: string) => ({ name: v }))); - setDatabaseList(res.db_names); + try { + const res = await DatabaseHttp.getDatabases(); + setDatabases(res.db_names.map((v: string) => ({ name: v }))); + setDatabaseList(res.db_names); + } catch (error) { + // do nothing + } }; const handleCreate = async (data: CreateDatabaseParams) => {