回调不是函数NODEJS

时间:2019-02-23 14:48:52

标签: callback

我正在尝试学习nodejs并偶然发现此错误

  

callback(为null,已删除);
  TypeError:回调不是函数

这是一个Steam交易机器人,因此当它向我发送要约时,我接受了要约,但随后崩溃了。怎么了?

exports.removeOweNoTitle = (user, callback) => {
    let file = 'data/users/' + user + '.json';

    if(fs.existsSync(file)) {
        let read = fs.createReadStream(file);

        let data = "";

        read.on('data', (chunk) => {
            data += chunk;
        });

        read.on('end', () => {
            let json;

            try {
                json = JSON.parse(data);
            } catch(error) {
                return callback(error);
            }

            let owe = {};

            if(json.owe) 
                owe = json.owe;
            else {
                callback(null, 0);
                return;
            }

            let removed = 0;
            for(let game in owe) {
                if(owe[game]) {
                    removed += owe[game];
                    owe[game] = 0;
                }
            }

            let write = fs.createWriteStream(file, {flags: 'w'});

            exports.clearNotifications(user, () => {
                write.write(JSON.stringify(json), (error) => {
                    if(error)
                        return callback(error);

                    write.end();
                });
                return;
            });

            write.write(JSON.stringify(json), (error) => {
                if(error)
                    return callback(error);

                write.end();
            });

            write.on("finish", (callback, error) => {
                callback(null, removed);   //tady  nebyl deklarován callback chyběl
            });
        });
    } else {
        generateUserFile(user);
        callback(new Error('User\'s file is not defined!'), null);
    }

}

0 个答案:

没有答案