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/ServerPage.js | |
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/ServerPage.js')
-rw-r--r-- | modern/src/settings/ServerPage.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/modern/src/settings/ServerPage.js b/modern/src/settings/ServerPage.js index 5fdba47b..b745cb96 100644 --- a/modern/src/settings/ServerPage.js +++ b/modern/src/settings/ServerPage.js @@ -15,6 +15,7 @@ import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; import useCommonDeviceAttributes from '../common/attributes/useCommonDeviceAttributes'; import useCommonUserAttributes from '../common/attributes/useCommonUserAttributes'; +import { useCatch } from '../reactHelper'; const useStyles = makeStyles((theme) => ({ container: { @@ -44,7 +45,7 @@ const ServerPage = () => { const original = useSelector((state) => state.session.server); const [item, setItem] = useState({ ...original }); - const handleSave = async () => { + const handleSave = useCatch(async () => { const response = await fetch('/api/server', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, @@ -54,8 +55,10 @@ const ServerPage = () => { if (response.ok) { dispatch(sessionActions.updateServer(await response.json())); history.goBack(); + } else { + throw Error(await response.text()); } - }; + }); return ( <PageLayout menu={<SettingsMenu />} breadcrumbs={['settingsTitle', 'settingsServer']}> |