summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/traffic.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/api/traffic.js b/src/api/traffic.js
index 63252aa..3e1c780 100644
--- a/src/api/traffic.js
+++ b/src/api/traffic.js
@@ -72,14 +72,23 @@ function pump(reader) {
function fetchData(apiConfig) {
if (fetched) return traffic;
+ fetched = true;
const { url, init } = getURLAndInit(apiConfig);
- fetch(url + endpoint, init).then(response => {
- if (response.ok) {
- fetched = true;
- const reader = response.body.getReader();
- pump(reader);
+ fetch(url + endpoint, init).then(
+ response => {
+ if (response.ok) {
+ const reader = response.body.getReader();
+ pump(reader);
+ } else {
+ fetched = false;
+ }
+ },
+ err => {
+ // eslint-disable-next-line no-console
+ console.log('fetch /traffic error', err);
+ fetched = false;
}
- });
+ );
return traffic;
}