catch error from google trends API, let it result in empty array
Этот коммит содержится в:
родитель
f3713af07e
Коммит
60ed620c13
@ -115,7 +115,8 @@
|
|||||||
data: await loadGoogleTrendsData('disinformation'),
|
data: await loadGoogleTrendsData('disinformation'),
|
||||||
selected: false
|
selected: false
|
||||||
}
|
}
|
||||||
];
|
]
|
||||||
|
.filter((d) => d.data.length > 0);
|
||||||
|
|
||||||
preloadImages(data);
|
preloadImages(data);
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
import { googleTrendsApiPath } from '../inputs/dataPaths';
|
import { googleTrendsApiPath } from '../inputs/dataPaths';
|
||||||
|
|
||||||
const loadGoogleTrendsData = async (keyword) => {
|
const loadGoogleTrendsData = async (keyword) => {
|
||||||
|
let data = [];
|
||||||
|
try {
|
||||||
const response = await fetch(`${googleTrendsApiPath}${encodeURIComponent(keyword)}`);
|
const response = await fetch(`${googleTrendsApiPath}${encodeURIComponent(keyword)}`);
|
||||||
const data = (await response.json()).map((d) => ({
|
data = (await response.json()).map((d) => ({
|
||||||
...d,
|
...d,
|
||||||
date: new Date(d.time * 1000)
|
date: new Date(d.time * 1000)
|
||||||
}));
|
}))
|
||||||
console.log(data)
|
.filter((d) => !d.isPartial);
|
||||||
return(data.filter((d) => !d.isPartial));
|
} finally {
|
||||||
|
return(data);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadGoogleTrendsData;
|
export default loadGoogleTrendsData;
|
||||||
|
|||||||
Загрузка…
x
Ссылка в новой задаче
Block a user