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