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/reports/StatisticsPage.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/reports/StatisticsPage.js')
-rw-r--r-- | modern/src/reports/StatisticsPage.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/modern/src/reports/StatisticsPage.js b/modern/src/reports/StatisticsPage.js index 214773fe..b1652468 100644 --- a/modern/src/reports/StatisticsPage.js +++ b/modern/src/reports/StatisticsPage.js @@ -9,6 +9,7 @@ import ReportsMenu from './components/ReportsMenu'; import ReportFilter from './components/ReportFilter'; import usePersistedState from '../common/util/usePersistedState'; import ColumnSelect from './components/ColumnSelect'; +import { useCatch } from '../reactHelper'; const columnsArray = [ ['captureTime', 'statisticsCaptureTime'], @@ -30,13 +31,15 @@ const StatisticsPage = () => { const [columns, setColumns] = usePersistedState('statisticsColumns', ['captureTime', 'activeUsers', 'activeDevices', 'messagesStored']); const [items, setItems] = useState([]); - const handleSubmit = async (_, from, to) => { + const handleSubmit = useCatch(async (_, from, to) => { const query = new URLSearchParams({ from, to }); const response = await fetch(`/api/statistics?${query.toString()}`, { Accept: 'application/json' }); if (response.ok) { setItems(await response.json()); + } else { + throw Error(await response.text()); } - }; + }); return ( <PageLayout menu={<ReportsMenu />} breadcrumbs={['reportTitle', 'statisticsTitle']}> |