javascript - provide HTTP status to the success callback of $resource -


i need status code of factory promises, how can it?

myapp.factory('cartservice', ['$resource', function($resource){   return $resource('/api/v1/carts ', {}, {     show: { method: 'get', isarray:false, headers:{'authorization':'token token=' + localstorage.token} },     create: { method: 'post', headers:{'authorization':'token token=' + localstorage.token} }   }) }]); 

this call

cartservice.show().$promise.then(function(data){         $rootscope.cart = data;         // status ????       }).catch(function(response){         growl.warning("problems!!", {title: 'error'});       }) 

the response has status 204

enter image description here

as said in this answer,

you have add interceptor $ressource call. in interceptor, can add $http response promise response.

code this:

var resource = $resource(url, {}, {     get: {         method: 'get'         interceptor: {             response: function(response) {                       var result = response.resource;                         result.$status = response.status;                 return result;             }         }     }                             }); 

i suggest check original answer.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -