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/other | |
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/other')
-rw-r--r-- | modern/src/other/EventPage.js | 4 | ||||
-rw-r--r-- | modern/src/other/PositionPage.js | 2 | ||||
-rw-r--r-- | modern/src/other/ReplayPage.js | 7 |
3 files changed, 11 insertions, 2 deletions
diff --git a/modern/src/other/EventPage.js b/modern/src/other/EventPage.js index 46f5e67c..7bcf90a8 100644 --- a/modern/src/other/EventPage.js +++ b/modern/src/other/EventPage.js @@ -37,6 +37,8 @@ const EventPage = () => { const response = await fetch(`/api/events/${id}`); if (response.ok) { setEvent(await response.json()); + } else { + throw Error(await response.text()); } } }, [id]); @@ -49,6 +51,8 @@ const EventPage = () => { if (positions.length > 0) { setPosition(positions[0]); } + } else { + throw Error(await response.text()); } } }, [event]); diff --git a/modern/src/other/PositionPage.js b/modern/src/other/PositionPage.js index 4c13955a..76bb560f 100644 --- a/modern/src/other/PositionPage.js +++ b/modern/src/other/PositionPage.js @@ -41,6 +41,8 @@ const PositionPage = () => { if (positions.length > 0) { setItem(positions[0]); } + } else { + throw Error(await response.text()); } } else { setItem({}); diff --git a/modern/src/other/ReplayPage.js b/modern/src/other/ReplayPage.js index 9bdf87be..c1c56ac1 100644 --- a/modern/src/other/ReplayPage.js +++ b/modern/src/other/ReplayPage.js @@ -18,6 +18,7 @@ import PositionsMap from '../map/PositionsMap'; import { formatTime } from '../common/util/formatter'; import ReportFilter from '../reports/components/ReportFilter'; import { useTranslation } from '../common/components/LocalizationProvider'; +import { useCatch } from '../reactHelper'; const useStyles = makeStyles((theme) => ({ root: { @@ -121,7 +122,7 @@ const ReplayPage = () => { } }, [index, positions]); - const handleSubmit = async (deviceId, from, to, _, headers) => { + const handleSubmit = useCatch(async (deviceId, from, to, _, headers) => { setSelectedDeviceId(deviceId); const query = new URLSearchParams({ deviceId, from, to }); const response = await fetch(`/api/positions?${query.toString()}`, { headers }); @@ -129,8 +130,10 @@ const ReplayPage = () => { setIndex(0); setPositions(await response.json()); setExpanded(false); + } else { + throw Error(await response.text()); } - }; + }); return ( <div className={classes.root}> |