2013-03-27 1 views
1

Facebook에 Node.js Heroku 앱이 있습니다. 로그에 다음 오류가 계속 표시됩니다. 실제로 내 애플리케이션에 액세스하려고 할 때 일반적인 애플리케이션 오류가 발생합니다. 응용 프로그램) :SyntaxError : JSON 본문을 구문 분석하지 못했습니다. 예기치 않은 토큰 o

내 서버 코드에서
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을 사용하고 있습니다 console.log(data + ': is in the tags table, with tag_id=' + JSON.stringify(result)); 여기서 result은 쿼리에서 Postgres 데이터베이스로 반환되는 응답입니다. 그러나 나는 결코 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.???? 예를 들어, 각 행 req.friendsreq.friends = friends;과 같이 사용되었으므로 즉, JSON.parseJSON.stringify 두 가지를 모두 추가했으며 변경된 사항은 없습니다. 앞서 언급 한 바와 같이

+0

당신이 게시 할 수 있습니다 (내가하라는 덕분에!) 문자열 결과 – user568109

+1

그것은 restler의 버그로 인한 것일 수 있습니다. https://github.com/heroku/faceplate/issues/26 – user568109

+0

@ user568109, 'client.query ('select tag_id FROM tags where tag_text = \ ''+ data, 'data', 'data', 'function'(err, result) {'는 결과를 얻는 줄입니다. 전에는 문제가 없었습니다. 결과가 실제로 무엇인지는 문자열이 아니므로 [here] (https://devcenter.heroku.com/ar) 예제에 따라 JSON.stringify()를 사용합니다. ticles/heroku-postgresql # 연결 노드에서). 또한 나는 레스트 러를 사용하지 않고있다. –

답변

1

,이 솔루션은 여기에서 찾을 수 있습니다 : https://github.com/heroku/faceplate/issues/26 페이스 플레이트의 0.0.4 버전을 위해 그것을 해결에 대한 더욱 자세한 사항이 있다고하더라도 그것은 주목해야한다

관련 문제