对象#<incomingmessage>没有方法&#39; serverError&#39;

时间:2015-10-28 19:42:21

标签: mysql error-handling google-cloud-messaging sails.js waterline

我在ubuntu上使用node.js:sailsjs

node version: 0.10.37
sails version: 0.11.0
npm version: 1.4.28
ubuntu version: 14.04.2

我正在尝试将GCM推送通知服务返回的值记录到mysql表中。我正在登录db表的推送通知服务(PushNotifications.js文件)的部分如下所示:

var req = https.request(options, function(res) {
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
        console.log('Response from GCM: ' + chunk);
                    GcmLog.add(recipients, chunk, function(err, response){
                        if(err){
                            res.serverError(err);
                        }else{
                            res.json({msg: 'yes'});
                        }
                    });
    });
});

GcmLog.js模型具有以下函数将数据推送到db表中:

  add: function(device_id, chunk, callback){
        GcmLog.create({user: device_id, log: chunk}).exec(function(err, response){
            if(err){
                return callback(err, null);
            }else{
        callback(null, response);
      }
    });
  }

当我发送推送通知时,消息传递成功并显示在Android设备上,但没有任何内容记录到数据库表中。我在应用程序的日志文件中收到以下错误:

/path/to/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Parser.js:82
        throw err;
              ^
TypeError: Object #<IncomingMessage> has no method 'serverError'
    at /path/to/api/services/PushNotifications.js:44:13
    at /path/to/api/models/GcmLog.js:29:12
    at bound (/path/to/node_modules/sails/node_modules/lodash/dist/lodash.js:957:21)
    at applyInOriginalCtx (/path/to/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:416:80)
    at wrappedCallback (/path/to/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:326:16)
    at _normalizeCallback.callback.error (/path/to/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/normalize.js:42:31)
    at _switch (/path/to/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/factory.js:46:28)
    at /path/to/node_modules/sails/node_modules/waterline/lib/waterline/query/dql/create.js:216:14
    at bound (/path/to/node_modules/sails/node_modules/lodash/dist/lodash.js:957:21)
    at applyInOriginalCtx (/path/to/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:416:80)
    at wrappedCallback (/path/to/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:326:16)
    at _normalizeCallback.callback.error (/path/to/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/normalize.js:42:31)
    at _switch (/path/to/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/factory.js:46:28)
    at afterwards (/path/to/node_modules/sails/node_modules/waterline/lib/waterline/adapter/dql.js:88:16)
    at bound (/path/to/node_modules/sails/node_modules/lodash/dist/lodash.js:957:21)
    at applyInOriginalCtx (/path/to/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:416:80)
error: Forever detected script exited with code: 8

然后服务器在多次尝试后崩溃并重新启动。我无法找出原因。任何帮助解释正在发生的事情以及如何克服这一点,将不胜感激。

0 个答案:

没有答案