I have a function that does ajax calls, another one that handles errors. The target is: Manipulate the error into a better format to use later (see example below).
The problem: The second callback for .then()
isn't called though.
The code:
function _handleError(error) {
//bring error info in better usable format
...
return errorRes;
}
function getSth(...) {
...
return $.ajax({
url: baseUrl + query,
type: "GET",
headers: {
...
}
}).then(function (data) {
var results = data.d.results;
... //Do mapping stuff
return results;
}, _handleError);
}
How I would like to implement it:
getSth(...).then(function(results){
...
}, function(err){
console.log(err);
... //Do more with error info
});
The second function given to .then()
never gets called, _handleError()
is though. I'm quite sure I misunderstood something on Promise concepts.