I have promisified the fbgraph nodeJS API and am using it to test a feature. This feature posts to a given Facebook Group, then verifies the post has gone through correctly and deletes the post. The purpose of this code is to test that the user has post permissions for a different array of groups.
The code as it's currently implemented using Bluebird's Promise library, and generators.
var examplePostId = 12345678910
facebookPoster = Promise.coroutine(function* (feedId) {
var postResponse = yield graph.postAsync(feedId + '/feed', sampleData);
var postId = postResponse.id
var getResponse = yield graph.getAsync(postId)
var returnedId = getResponse.id
var postedSuccessfully = true // <-- This is what I want to reference in my error handler.
var deleteResponse = yield graph.delAsync(postId)
var getAfterDeleteResponse = yield graph.getAsync(postId) // I expect this to throw an error since the post should already be deleted
return postId
})
facebookPoster(examplePostId).then(function(postId){
console.log(postId);
}).catch(function(err){
console.log(err); // How can I tell the handler that error is fine because postedSuccessfully is true?
})
Here's my snafu: FB's Graph API is horrifically unreliable. Even if the post is not actually deleted, I will still receive a success response (documented here: ___).
Therefore, in my generator I am attempting to GET the information for the postID a second time, and am expecting it to blow up. When I do receive an error, it gets passed to my handler and my handler is triggered. This is fine, but I would like to be able to reference the postedSuccessfully boolean value to differentiate between an error that I was expecting to receive, and an error that was unexpected.
How can I reference the postedSuccessfully boolean value, or implement another graceful way to differentiate between the received errors?