aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/components/PositionValue.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-21 09:49:26 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-21 09:49:26 -0700
commit7e96816f94314dcdf071eeee6e74a95bcace329f (patch)
tree21938fcdbe6e8b7a651308555af77c49dc59e1c2 /modern/src/common/components/PositionValue.js
parent79dd42f0bdeef6d9f6331c0ec8301b2631a9cb90 (diff)
downloadtrackermap-web-7e96816f94314dcdf071eeee6e74a95bcace329f.tar.gz
trackermap-web-7e96816f94314dcdf071eeee6e74a95bcace329f.tar.bz2
trackermap-web-7e96816f94314dcdf071eeee6e74a95bcace329f.zip
Implement API error handling
Diffstat (limited to 'modern/src/common/components/PositionValue.js')
-rw-r--r--modern/src/common/components/PositionValue.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/modern/src/common/components/PositionValue.js b/modern/src/common/components/PositionValue.js
index 9f679605..1162a150 100644
--- a/modern/src/common/components/PositionValue.js
+++ b/modern/src/common/components/PositionValue.js
@@ -7,6 +7,7 @@ import {
import { useAttributePreference, usePreference } from '../util/preferences';
import { useTranslation } from './LocalizationProvider';
import { useAdministrator } from '../util/permissions';
+import { useCatch } from '../../reactHelper';
const PositionValue = ({ position, property, attribute }) => {
const t = useTranslation();
@@ -26,7 +27,7 @@ const PositionValue = ({ position, property, attribute }) => {
setAddress(position.address);
}, [position]);
- const showAddress = async () => {
+ const showAddress = useCatch(async () => {
const query = new URLSearchParams({
latitude: position.latitude,
longitude: position.longitude,
@@ -34,8 +35,10 @@ const PositionValue = ({ position, property, attribute }) => {
const response = await fetch(`/api/server/geocode?${query.toString()}`);
if (response.ok) {
setAddress(await response.text());
+ } else {
+ throw Error(await response.text());
}
- };
+ });
const formatValue = () => {
switch (key) {