diff options
author | Anton Tananaev <anton@traccar.org> | 2022-10-04 17:37:01 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-10-04 17:37:01 -0700 |
commit | af52f4291dafef3f224d7a472b2fbcbe47dc2924 (patch) | |
tree | dedcc7baf5e77bd9f9990bf44e96e4a7646984bb /modern | |
parent | 033c88d5d4092f9daca90a3ef984deacd593a29e (diff) | |
download | trackermap-web-af52f4291dafef3f224d7a472b2fbcbe47dc2924.tar.gz trackermap-web-af52f4291dafef3f224d7a472b2fbcbe47dc2924.tar.bz2 trackermap-web-af52f4291dafef3f224d7a472b2fbcbe47dc2924.zip |
Handle network failures
Diffstat (limited to 'modern')
-rw-r--r-- | modern/src/SocketController.js | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/modern/src/SocketController.js b/modern/src/SocketController.js index 49874ba7..87b842fa 100644 --- a/modern/src/SocketController.js +++ b/modern/src/SocketController.js @@ -45,15 +45,19 @@ const SocketController = () => { socket.onclose = async (event) => { dispatch(sessionActions.updateSocket(false)); if (event.code !== logoutCode) { - const devicesResponse = await fetch('/api/devices'); - if (devicesResponse.ok) { - dispatch(devicesActions.update(await devicesResponse.json())); - } - const positionsResponse = await fetch('/api/positions', { - headers: { 'Content-Type': 'application/json' }, - }); - if (positionsResponse.ok) { - dispatch(positionsActions.update(await positionsResponse.json())); + try { + const devicesResponse = await fetch('/api/devices'); + if (devicesResponse.ok) { + dispatch(devicesActions.update(await devicesResponse.json())); + } + const positionsResponse = await fetch('/api/positions', { + headers: { 'Content-Type': 'application/json' }, + }); + if (positionsResponse.ok) { + dispatch(positionsActions.update(await positionsResponse.json())); + } + } catch (error) { + // ignore errors } setTimeout(() => connectSocket(), 60000); } |