[javascript] "Uncaught (in promise) undefined" error when using with=location in Facebook Graph API query

I am currently developing a web application with the Facebook Graph API.

My current goal is to retrieve only posts which have a location attached.

While retrieving posts with and without location is already working, I am not able to retrieve only posts with location.

The query which retrieves both types looks like this: '/me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location'

The query which should retrieve only posts with location looks like this: /me/feed?fields=id,name,message,picture,place,with_tags&limit=100&with=location

The problem I have is that with the parameter &with=location I get an error Uncaught (in promise) undefined at this part of my code:

if (response.paging && response.paging.next) {
    recursiveAPICall(response.paging.next);
  } else {
    resolve(postsArr);
  }
} else {
  // Error message comes from here
  reject();
}

Log shows the following:

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

Does anyone have a possible solution for this?

For further information how the code looks like see my previous question.

The answer is


The error tells you that there is an error but you don´t catch it. This is how you can catch it:

getAllPosts().then(response => {
    console.log(response);
}).catch(e => {
    console.log(e);
});

You can also just put a console.log(reponse) at the beginning of your API callback function, there is definitely an error message from the Graph API in it.

More information: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch

Or with async/await:

//some async function
try {
    let response = await getAllPosts();
} catch(e) {
    console.log(e);
}

The reject actually takes one parameter: that's the exception that occurred in your code that caused the promise to be rejected. So, when you call reject() the exception value is undefined, hence the "undefined" part in the error that you get.

You do not show the code that uses the promise, but I reckon it is something like this:

var promise = doSth();
promise.then(function() { doSthHere(); });

Try adding an empty failure call, like this:

promise.then(function() { doSthHere(); }, function() {});

This will prevent the error to appear.

However, I would consider calling reject only in case of an actual error, and also... having empty exception handlers isn't the best programming practice.


Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to facebook-graph-api

"Uncaught (in promise) undefined" error when using with=location in Facebook Graph API query Facebook OAuth "The domain of this URL isn't included in the app's domain" Facebook login message: "URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings." Facebook Graph API v2.0+ - /me/friends returns empty, or only friends who also use my application Creating a Facebook share button with customized url, title and image Facebook API "This app is in development mode" The developers of this app have not set up this app properly for Facebook Login? New og:image size for Facebook share? facebook: permanent Page Access Token? How to programmatically log out from Facebook SDK 3.0 without using Facebook login/logout button?

Examples related to facebook-javascript-sdk

Chrome violation : [Violation] Handler took 83ms of runtime "Uncaught (in promise) undefined" error when using with=location in Facebook Graph API query How to add facebook share button on my website? Given URL is not permitted by the application configuration How to get access token from FB.login method in javascript SDK Facebook API error 191 Facebook Javascript SDK Problem: "FB is not defined"