Я получаю следующую ошибку:
Houston we got an err at getGames in index.js
(node:72197) UnhandledPromiseRejectionWarning: #<Object>
(node:72197) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:72197) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
error at getGames rp
Вот соответствующий код:
Вспомогательная функция для получения данных из API (rp - это request-обещание-native)
const getGames = async () => {
return await rp(`https://api.steampowered.com/IDOTA2Match_570/GetTopLiveGame/v1?key=${KEY}&partner=0`)
.catch(err => console.log('error at getGames rp'))
.error(err => console.log('actual error at getGames rp'))
}
Я вызываю это каждые 5 секунд
app.get('/api/update', async (req, res) => {
const data = await getGames()
.catch(err => console.log('Houston we got an err at getGames in index.js'))
const dataJson = JSONbig.parse(data);
if (dataJson.game_list && dataJson.game_list.length) {
for (let i = 0; i < dataJson.game_list.length; i++) {
const game = dataJson.game_list[i];
...
Конечная точка '/ api / update' вызывается каждые 5 секунд. Я получаю вышеуказанную ошибку. Мой для l oop перестает повторяться. Я бы хотел, чтобы он пропустил тот, на котором ошибка, но он говорит, что я не обрабатываю ошибку. У меня есть блоки catch и даже блоки ошибок, и я не могу понять, почему это происходит.
Я также пытался вручную вызывать:
`https://api.steampowered.com/IDOTA2Match_570/GetTopLiveGame/v1?key=${KEY}&partner=0`
в почтальоне много раз в быстрая последовательность, но почтальон никогда не ошибается. Так что проблема в моем коде где-то. Я обработал все ошибки, поэтому я не могу найти то, что не обрабатываю.