diff options
author | Anton Tananaev <anton@traccar.org> | 2022-05-21 09:49:26 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-05-21 09:49:26 -0700 |
commit | 7e96816f94314dcdf071eeee6e74a95bcace329f (patch) | |
tree | 21938fcdbe6e8b7a651308555af77c49dc59e1c2 /modern/src/settings/components | |
parent | 79dd42f0bdeef6d9f6331c0ec8301b2631a9cb90 (diff) | |
download | trackermap-web-7e96816f94314dcdf071eeee6e74a95bcace329f.tar.gz trackermap-web-7e96816f94314dcdf071eeee6e74a95bcace329f.tar.bz2 trackermap-web-7e96816f94314dcdf071eeee6e74a95bcace329f.zip |
Implement API error handling
Diffstat (limited to 'modern/src/settings/components')
-rw-r--r-- | modern/src/settings/components/EditItemView.js | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/modern/src/settings/components/EditItemView.js b/modern/src/settings/components/EditItemView.js index 9b9918fe..28598e77 100644 --- a/modern/src/settings/components/EditItemView.js +++ b/modern/src/settings/components/EditItemView.js @@ -5,7 +5,7 @@ import Container from '@material-ui/core/Container'; import Button from '@material-ui/core/Button'; import FormControl from '@material-ui/core/FormControl'; -import { useEffectAsync } from '../../reactHelper'; +import { useCatch, useEffectAsync } from '../../reactHelper'; import { useTranslation } from '../../common/components/LocalizationProvider'; import PageLayout from '../../common/components/PageLayout'; @@ -36,13 +36,15 @@ const EditItemView = ({ const response = await fetch(`/api/${endpoint}/${id}`); if (response.ok) { setItem(await response.json()); + } else { + throw Error(await response.text()); } } else { setItem(defaultItem || {}); } }, [id]); - const handleSave = async () => { + const handleSave = useCatch(async () => { let url = `/api/${endpoint}`; if (id) { url += `/${id}`; @@ -59,8 +61,10 @@ const EditItemView = ({ onItemSaved(await response.json()); } history.goBack(); + } else { + throw Error(await response.text()); } - }; + }); return ( <PageLayout menu={menu} breadcrumbs={breadcrumbs}> |