Skip to content

Commit

Permalink
error handle for database
Browse files Browse the repository at this point in the history
Signed-off-by: ruiyi.jiang <[email protected]>
  • Loading branch information
shanghaikid committed Aug 8, 2023
1 parent b780680 commit f31a519
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 6 additions & 2 deletions client/src/context/Data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
const [databases, setDatabases] = useState<string[]>(['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(() => {
Expand Down
14 changes: 10 additions & 4 deletions client/src/pages/database/Database.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const Database = () => {
useNavigationHook(ALL_ROUTER_TYPES.DATABASES);
const { setDatabaseList } = useContext(dataContext);

const [databases, setDatabases] = useState<DatabaseData[]>([]);
const [databases, setDatabases] = useState<DatabaseData[]>([
{ name: 'default' },
]);
const [selectedDatabase, setSelectedDatabase] = useState<DatabaseData[]>([]);
const { setDialog, handleCloseDialog, openSnackBar } =
useContext(rootContext);
Expand All @@ -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) => {
Expand Down

0 comments on commit f31a519

Please sign in to comment.