Skip to content

Commit

Permalink
add error case for missing valuesets
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrund-tsi committed Jun 23, 2021
1 parent 6dffe69 commit 6ef17de
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/error-page.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ErrorPage = (props: any) => {
<hr />
<p className='text-center'>
<span className='font-weight-bold'>{t('translation:serverError')}</span>
<span>{props?.error?.message}</span>
<span>{props?.error ? props?.error?.message : props.message}</span>
</p>

<hr />
Expand Down
6 changes: 3 additions & 3 deletions src/misc/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

export default interface IError {
error: any;
message: string;
onCancel: () => void;
error?: any;
message?: string;
onCancel?: () => void;
}
18 changes: 15 additions & 3 deletions src/misc/useValueSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const useGetDateFormats = () => {
return dateFormats
}

export const useGetValueSets = (onInit?: (isInit: boolean) => void) => {
export const useGetValueSets = (onInit?: (isInit: boolean) => void, onError?: (msg: string) => void) => {

const [valueSetHashList, setValueSetHashList] = React.useState<IValueSetHashListItem[]>();

Expand All @@ -91,8 +91,20 @@ export const useGetValueSets = (onInit?: (isInit: boolean) => void) => {
const uri = '/valuesets';

valueSetApi.get(uri).then((response) => {
setValueSetHashList(response.data);
});
if (response && response.data && response.data.length > 0) {
setValueSetHashList(response.data);
}
else {
if (onError) {
onError('failed to request valuesets');
}
}
})
.catch((error) => {
if (onError) {
onError(error.message);
}
});

}, [])

Expand Down
4 changes: 2 additions & 2 deletions src/routing.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Routing = () => {

const context: IAppContext = {
navigation: useNavigation(),
valueSets: useGetValueSets(),
valueSets: useGetValueSets(undefined, (msg) => { setError({ message: msg }) }),
utils: utils
}

Expand All @@ -85,7 +85,7 @@ const Routing = () => {
*/}
<Route path={context.navigation.routes.root}>
<Header />
<ErrorPage error={error} show={errorShow} onCancel={error?.onCancel} onHide={() => setErrorShow(false)} />
<ErrorPage error={error} show={errorShow} onCancel={error?.onCancel ? error?.onCancel : context.navigation.toLanding} onHide={() => setErrorShow(false)} />
<DataprivacyPage show={dataPrivacyShow} setShow={setDataPrivacyShow} />
<ImprintPage show={imprintShow} setShow={setImprintShow} />
</Route>
Expand Down

0 comments on commit 6ef17de

Please sign in to comment.