javascript - Error handler in .then() not triggered unless .success and .error is used -


I am writing a function that handles results from a corner $ http. I handle the results in my $ http request To do this I am using .then ().

  var GET = function (url) {return $ http ({method: 'GET', url: url}). Then (function (data) {return data.data;}, function (data) {return data.data;}); };   

And then I call the GET function from some other function, such as:

  var initializeUsers = function () {return dbService.GET (serverUrl) + DbResource). Then (function (data) {// some code to be successful}, function (data) {// some code to handle error}}; };   

Here's the problem: If there is an error in the HTTP request, then it is being controlled by the error handler in the GET function. However, when initializeUsers is run, the error handler is not triggered, rather the success handler. Therefore the error is not "bubble", which

However, if I, .then , instead of using it in the GET function, I would .success and .error , such as:

  var GET = function (url) {return $ http ({method: 'GET', url: url}) .success (function (Data) {return data.data;}) Error (function (data) {return data.data;}); };   

This works fine in initializeUsers . However, if I call initializeUsers by another function using .then , then error handler is not triggered in it. I find that I have to use .success and .error in all ways, which is not to work, as far as I can understand . Unless I explicitly use .error on every function to capture the error, the error is lost and the next function works as if the previous one was successful.

Am I misunderstanding or something wrong in my code?

If you return a promise error callback from the callback , this is actually a solution (Not deny) will return the promise instead use throw and the resulting promise will be rejected ...

  var GET = function (url) {return $ Http ({method: 'GET', url: Url}). Then (function (data) {return data.data;}, function (data) {enter data data; data;};    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -