1

我在 Facebook 上有一个 Node.js Heroku 应用程序,并且我不断在日志中发现以下错误(当我实际尝试访问我的应用程序时出现一般应用程序错误):

2013-03-27T12:58:54+00:00 heroku[web.1]: Starting process with command `node web
.js`
2013-03-27T12:58:55+00:00 app[web.1]: info: socket.io started
2013-03-27T12:58:55+00:00 app[web.1]: Listening on 6925
2013-03-27T12:58:56+00:00 heroku[web.1]: State changed from starting to up
2013-03-27T13:00:40+00:00 app[web.1]: ^
2013-03-27T13:00:40+00:00 app[web.1]: undefined:1
2013-03-27T13:00:40+00:00 app[web.1]:
2013-03-27T13:00:40+00:00 app[web.1]: SyntaxError: Failed to parse JSON body: Un
expected token o
2013-03-27T13:00:40+00:00 app[web.1]:     at Object.parse (native)
2013-03-27T13:00:40+00:00 app[web.1]:     at EventEmitter.emit (events.js:99:17)

2013-03-27T13:00:40+00:00 app[web.1]: SyntaxError: Unexpected token S
2013-03-27T13:00:40+00:00 app[web.1]:     at EventEmitter.mixin._fireError (/app
/node_modules/faceplate/node_modules/restler/lib/restler.js:192:10)
2013-03-27T13:00:40+00:00 app[web.1]:     at IncomingMessage.parsers.json (/app/
node_modules/faceplate/node_modules/restler/lib/restler.js:367:9)
2013-03-27T13:00:40+00:00 app[web.1]:     at EventEmitter.FaceplateSession.get (
/app/node_modules/faceplate/index.js:121:25)
2013-03-27T13:00:40+00:00 app[web.1]:     at mixin._responseHandler (/app/node_m
odules/faceplate/node_modules/restler/lib/restler.js:142:20)
2013-03-27T13:00:40+00:00 app[web.1]:     at EventEmitter.mixin._encode (/app/no
de_modules/faceplate/node_modules/restler/lib/restler.js:184:29)
2013-03-27T13:00:40+00:00 app[web.1]:     at IncomingMessage.parsers.auto (/app/
node_modules/faceplate/node_modules/restler/lib/restler.js:356:21)
2013-03-27T13:00:40+00:00 app[web.1]:     at mixin._responseHandler (/app/node_m
odules/faceplate/node_modules/restler/lib/restler.js:140:16)
2013-03-27T13:00:40+00:00 app[web.1]:     at EventEmitter.mixin._decode (/app/no
de_modules/faceplate/node_modules/restler/lib/restler.js:156:7)
2013-03-27T13:00:41+00:00 heroku[web.1]: Process exited with status 1
2013-03-27T13:00:41+00:00 heroku[web.1]: State changed from up to crashed

在我的服务器代码中,我使用的是JSON.stringify,例如从查询返回到 Postgres 数据库的答案console.log(data + ': is in the tags table, with tag_id=' + JSON.stringify(result));在哪里。result但是,我从不使用JSON.parse,所以这个错误有点令人困惑,直到今天我也从未遇到过这个错误(我的应用程序在周一运行良好)。

同样令人困惑的是,如果我注释掉这些JSON.stringify调用,我仍然会收到错误消息,因此非常感谢任何想法!

根据https://github.com/heroku/faceplate/issues/26,我对我的代码进行了以下更改:

function handle_facebook_request(req, res) {

  // if the user is logged in
  if (req.facebook.token) {

 async.parallel([
  function(cb) {
    // query 4 friends and send them to the socket for this socket id
    req.facebook.get('/me/friends', { limit: 4 }, function(friends) {
      req.friends = JSON.parse(JSON.stringify(friends));
      cb();
    });
  },
  function(cb) {
    // query 16 photos and send them to the socket for this socket id
    req.facebook.get('/me/photos', { limit: 16 }, function(photos) {
      req.photos = JSON.parse(JSON.stringify(photos));
      cb();
    });
  },
  function(cb) {
    // query 4 likes and send them to the socket for this socket id
    req.facebook.get('/me/likes', { limit: 4 }, function(likes) {
      req.likes = JSON.parse(JSON.stringify(likes));
      cb();
    });
  },
  function(cb) {
    // use fql to get a list of my friends that are using this app
    req.facebook.fql('SELECT uid, name, is_app_user, pic_square FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1', function(result) {
      req.friends_using_app = JSON.parse(JSON.stringify(result));
      cb();
    });
  }
], function() {
  render_page(req, res);
});

  } else {
    render_page(req, res);
  }
}

req.????带有eg的每一行req.friends过去就像req.friends = friends;ie 我添加了JSON.parseJSON.stringify调用一样,没有任何改变。

4

1 回答 1

1

如前所述,可以在此处找到解决方案:https ://github.com/heroku/faceplate/issues/26应该注意的是,现在有更多关于修复 0.0.4 版面板的详细信息(感谢我的提示!)

于 2013-04-03T19:33:54.310 回答