0
我正在使用Facebook图形API,并且遇到了处理失败请求的麻烦。HTTP.call抛出错误而不是返回响应
我用这个代码来创建一个新的职位
SocialFacebook.createPosting = function(data) {
var options = {
params: {
access_token : data.tokens.accessToken,
message : data.text
}
};
var url = 'https://graph.facebook.com/' + data.graphId + '/feed';
var response = HTTP.call('POST', url, options).data;
return response;
}
但不是返回响应结果中的错误信息的JS对象,它抛出对失败的请求错误
Exception while invoking method 'createPosting' Error: failed [500] {"error":{"message":"Duplicate status message","type":"FacebookApiException","code":506,"error_subcode":1455006,"is_transient":false,"error_user_title":"Duplicate Status Update","error_user_msg":"This status update is identical to the last one you posted. Try posting something different, or delete your previous update."}}
因为它包装在Error
中,否则JSON对象现在是一个字符串,并附加了一些其他内容,这使得难以解析和提取属性
任何想法为什么它会抛出一个错误,而不是像通常那样返回带有错误细节的JS对象?
非常感谢
啊我看到了,所以我想唯一的方法来获取JSON错误是将请求包装在wrapAsync/runSync中? – Tarlen
是的,这是我猜测的一种方式,或者你可以尝试在'HTTP.call()'语句周围使用'try' /'catch'? – SylvainB
是的,但我仍然不得不手动剪切/解析字符串 – Tarlen