From 15bbad7dfeb76d6f72a6bf9ae31a0aa7c30a2dbf Mon Sep 17 00:00:00 2001 From: monoid Date: Wed, 29 Jun 2022 17:02:57 +0900 Subject: [PATCH] feat: show error msg --- src/client/page/gallery.tsx | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/client/page/gallery.tsx b/src/client/page/gallery.tsx index e3f4cfa..16fbd53 100644 --- a/src/client/page/gallery.tsx +++ b/src/client/page/gallery.tsx @@ -8,6 +8,8 @@ import { toQueryString } from '../accessor/util'; import { useLocation } from 'react-router-dom'; import { QueryStringToMap } from '../accessor/util'; + + export type GalleryProp = { option?: QueryListOption; diff: string; @@ -18,26 +20,35 @@ type GalleryState = { export const GalleryInfo = (props: GalleryProp) => { const [state, setState] = useState({ documents: undefined }); + const [error, setError] = useState(null); const [loadAll, setLoadAll] = useState(false); useEffect(() => { const abortController = new AbortController(); console.log('load first',props.option); const load = (async () => { - const c = await ContentAccessor.findList(props.option); - //todo : if c is undefined, retry to fetch 3 times. and show error message. - setState({ documents: c }); - setLoadAll(c.length == 0); - }) + try{ + const c = await ContentAccessor.findList(props.option); + //todo : if c is undefined, retry to fetch 3 times. and show error message. + setState({ documents: c }); + setLoadAll(c.length == 0); + } + catch(e){ + if(e instanceof Error){ + setError(e.message); + } + else{ + setError("unknown error"); + } + } + }); load(); }, [props.diff]); const queryString = toQueryString(props.option ?? {}); - - if (state.documents === undefined) { + if (state.documents === undefined && error == null) { return (); } else { return ( - { ))} } { - state.documents.map(x => { + state.documents && state.documents.map(x => { return (); }) } + {(error && Error : {error})} {state.documents.length} loaded... + }}>{state.documents ? state.documents.length : "null"} loaded... );