"Uncaught (in promise) undefined" 在 Facebook Graph API 查询中使用 with=location 时出错
"Uncaught (in promise) undefined" error when using with=location in Facebook Graph API query
我目前正在使用 Facebook Graph 开发 Web 应用程序 API。
我目前的目标是只检索附有位置的帖子。
虽然可以检索带位置和不带位置的帖子,但我无法仅检索带位置的帖子。
检索两种类型的查询如下所示:'/me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location'
应该只检索带有位置的帖子的查询如下所示:/me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location
我遇到的问题是,使用参数 &with=location
我在代码的这一部分收到错误 Uncaught (in promise) undefined
:
if (response.paging && response.paging.next) {
recursiveAPICall(response.paging.next);
} else {
resolve(postsArr);
}
} else {
// Error message comes from here
reject();
}
日志显示如下:
DEBUG: -------------------------------
DEBUG: Ember : 2.4.5
DEBUG: Ember Data : 2.5.3
DEBUG: jQuery : 2.2.4
DEBUG: Ember Simple Auth : 1.1.0
DEBUG: -------------------------------
Object {error: Object}
error: Objectcode:
code: 1
1fbtrace_id: "H5cXMe7TJIn"
message: "An unknown error has occurred."
type: "OAuthException"
__proto__: Object
__proto__: Object
Uncaught (in promise) undefined
有人对此有解决方案吗?
有关代码的更多信息,请参阅我的 。
错误告诉你有一个错误,但你没有发现它。这是你如何捕捉它:
getAllPosts().then(response => {
console.log(response);
}).catch(e => {
console.log(e);
});
你也可以在你的API回调函数的开头放一个console.log(reponse)
,里面肯定有GraphAPI的错误信息。
更多信息:https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
或 async/await:
//some async function
try {
let response = await getAllPosts();
} catch(e) {
console.log(e);
}
reject
实际上有一个参数:那是您的代码中发生的导致承诺被拒绝的异常。因此,当您调用 reject()
时,异常值是 undefined
,因此您得到的错误中的 "undefined" 部分。
你没有显示使用 promise 的代码,但我认为它是这样的:
var promise = doSth();
promise.then(function() { doSthHere(); });
尝试添加一个空的失败调用,如下所示:
promise.then(function() { doSthHere(); }, function() {});
这将防止错误出现。
但是,我会考虑仅在出现实际错误的情况下调用 reject
,而且...拥有空的异常处理程序并不是最佳编程实践。
我目前正在使用 Facebook Graph 开发 Web 应用程序 API。
我目前的目标是只检索附有位置的帖子。
虽然可以检索带位置和不带位置的帖子,但我无法仅检索带位置的帖子。
检索两种类型的查询如下所示:'/me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location'
应该只检索带有位置的帖子的查询如下所示:/me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location
我遇到的问题是,使用参数 &with=location
我在代码的这一部分收到错误 Uncaught (in promise) undefined
:
if (response.paging && response.paging.next) {
recursiveAPICall(response.paging.next);
} else {
resolve(postsArr);
}
} else {
// Error message comes from here
reject();
}
日志显示如下:
DEBUG: -------------------------------
DEBUG: Ember : 2.4.5
DEBUG: Ember Data : 2.5.3
DEBUG: jQuery : 2.2.4
DEBUG: Ember Simple Auth : 1.1.0
DEBUG: -------------------------------
Object {error: Object}
error: Objectcode:
code: 1
1fbtrace_id: "H5cXMe7TJIn"
message: "An unknown error has occurred."
type: "OAuthException"
__proto__: Object
__proto__: Object
Uncaught (in promise) undefined
有人对此有解决方案吗?
有关代码的更多信息,请参阅我的
错误告诉你有一个错误,但你没有发现它。这是你如何捕捉它:
getAllPosts().then(response => {
console.log(response);
}).catch(e => {
console.log(e);
});
你也可以在你的API回调函数的开头放一个console.log(reponse)
,里面肯定有GraphAPI的错误信息。
更多信息:https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
或 async/await:
//some async function
try {
let response = await getAllPosts();
} catch(e) {
console.log(e);
}
reject
实际上有一个参数:那是您的代码中发生的导致承诺被拒绝的异常。因此,当您调用 reject()
时,异常值是 undefined
,因此您得到的错误中的 "undefined" 部分。
你没有显示使用 promise 的代码,但我认为它是这样的:
var promise = doSth();
promise.then(function() { doSthHere(); });
尝试添加一个空的失败调用,如下所示:
promise.then(function() { doSthHere(); }, function() {});
这将防止错误出现。
但是,我会考虑仅在出现实际错误的情况下调用 reject
,而且...拥有空的异常处理程序并不是最佳编程实践。