From 7e96816f94314dcdf071eeee6e74a95bcace329f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 21 May 2022 09:49:26 -0700 Subject: Implement API error handling --- modern/src/settings/ServerPage.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'modern/src/settings/ServerPage.js') 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 ( } breadcrumbs={['settingsTitle', 'settingsServer']}> -- cgit v1.2.3