summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaishan <[email protected]>2019-07-06 21:33:05 +0800
committerHaishan <[email protected]>2019-07-06 21:48:22 +0800
commitd67eb1b43150eb87325d4c5eaae8101ea7ac0ee7 (patch)
tree4e3aee5f8ea9175a1f0b60f4e152dc9098f61726 /src
parentbd49c0a3f93ebc83ebff0fe6a70f3d5f907489cc (diff)
fix(traffic): prevent GET /traffic being called multiple times
Diffstat (limited to 'src')
-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;
}