@thewayofmagic

Где ошибка в коде?

Делал вывод на телефон через api qiwi, выходит ошибка:
(node:2748) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined
    at C:\Users\Andre\Desktop\YCH cryptowallet\node_modules\node-qiwi-api\lib\callbackApi.js:759:39
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2748) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2748) [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.

Вот код:
vk.updates.hear(/^Пополнить телефон/, async (msg)=> {
    var keyboard = Keyboard.keyboard([[
        Keyboard.textButton({
            label: `Отмена`,
            color:
            Keyboard.SECONDARY_COLOR
        })
    ]])
    const sum = await msg.question({ keyboard, message: `Введите сумму пополнения в рублях`})
    if(/Отмена/i.test(sum.text)) {
        msg.send({
            message: `Вы вернулись в меню платежей.`,
            keyboard: profilekeyboard
        })
        return
    }
    const num = await msg.question(`Введите кошелёк без знака "+"`)
    if(/Отмена/i.test(num.text)) {
        msg.send({
            message: `Вы вернулись в меню платежей.`,
            keyboard: profilekeyboard
        })
        return
    }
    var nums = Number(num.text)
    if(!nums) {
        msg.send({
            message: `Вы ввели некорректный номер.`,
            keyboard: profilekeyboard
        })
        return
    }
    if(num.text.length < 11) {
        msg.send({
            message: `Вы ввели некорректный номер.`,
            keyboard: profilekeyboard
        })
        return
    }

    sum1 = sum / 100 * 2
    sum2 = sum1 + sum
    callbackWallet.toMobilePhone({ amount: `${sum.text}`, comment: ``, account: `${num.text}` }, (err, data) => {
        if (err) {
          console.log(err)
          }
        Wallet.getBalance((err, balance) => {
        if (balance.accounts[0].balance.amount < sum2) return msg.error(`Для совершения платежа на балансе должно быть не менее ${sum2} ₽`);
        if (!errorCode) {
          msg.send(`Платёж успешно обработан. Списано ${sum2} ₽`);
        }
    })
    })
})
  • Вопрос задан
  • 120 просмотров
Решения вопроса 1
bingo347
@bingo347 Куратор тега Node.js
Crazy on performance...
В данном коде нет данной ошибки.
Но неплохо бы научится читать саму ошибку, а не бежать за помощью в интернет:
TypeError: Cannot read property 'data' of undefined
Не могу прочитать свойство data из undefined

У Вас где-то происходит обращение к свойству data из переменной содержащей undefined
И не просто где-то, в тексте ошибки и это есть:
at C:\Users\Andre\Desktop\YCH cryptowallet\node_modules\node-qiwi-api\lib\callbackApi.js:759:39
в файле C:\Users\Andre\Desktop\YCH cryptowallet\node_modules\node-qiwi-api\lib\callbackApi.js
на строке 759 символ 39
Вы можете зайти туда и посмотреть, а что за функцию Вы вызвали неправильно
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы