Given I have a rejected promise:
var promise = new Promise(function(resolve, reject) {
reject({error_message: "Foo"});
});
And I want to transform that promise (in that case: extract the error message):
var new_promise = promise.then(function(response) {
return response.id;
}, function(error) {
return error.error_message;
});
When I run that promise again:
new_promise.then(function(id) {
console.log("Object created: "+id);
}, function(message) {
console.log("Error: "+message);
});
I'll always get Object created: Foo
on the console. It seems like the transformation turns the rejected promise into a resolved promise.
Is there a way to transform a rejected promise so the result is another rejected promise?