I am using durandal.. I have a base controller that manage the calls to the server... every controller, specialized per use case, use the base controller to do the call to the server. In the base controller I have this code:
self.call = function (url, type, data, success) {
return Q.when(
$.ajax({
...
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 500) {
// Do some work
}
}
})
);
Then, in my specialized controller I have
myController.execute(command)
.then(function () {
//Do work ok
})
.fail(function (data) {
//Manage error
});
the execute method, internally call the call
method I wrote at the start...
The problem of this solution is that when I manage the error in the base controller, then I execute also the fail
code in the specialized controller...
Another way I tried... in the base controller
self.call = function (url, type, data, success) {
return Q.fail(function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 500) {
app.showError("a new error");
}
else
throw { "jqXHR": jqXHR, "textStatus": textStatus, "errorThrown": errorThrown };
});
In this case, the then
code is executed in the specialized controller. How can I avoid to stop the propagation of the promise in this case?
Thank you