Re: Handling non-200 responses with $resource

2,435 views
Skip to first unread message

a.boro...@gmail.com

unread,
Jul 6, 2012, 3:51:55 PM7/6/12
to ang...@googlegroups.com
Hello!

You should use one function for success execution and oanother function for failure.

Stuff.get({stuff:$routeParams.stuffId}, function(response, getReponseHeaders) {
  // Here is success handler.
}, function(response, getReponseHeaders) {
  // Here is failure handler.
  if(response.status === 404) {
    // Do something for error 404
  }
}



On Friday, July 6, 2012 9:46:00 PM UTC+2, dylst wrote:
Hello!

I'm trying to handle non-200 status codes while using $resource, and I can't seem to get access to this data.

Stuff.get({stuff:$routeParams.stuffId}, function(response, getReponseHeaders) {
  // on a 404, this block is never reached
}

I'm assuming I must be doing something wrong?

I checked the angular-resource source code, and I'm able to get the response code within the "then" block.
See my comment here:  https://gist.github.com/3062339.   Should this promise include a .fail() block perhaps (javascript n00b speaking here)? 

Before I dug into this unnecessarily, I thought I'd ask, as I'm assuming I'm making a simple mistake.

Any suggestions welcome.  Thanks!
Reply all
Reply to author
Forward
0 new messages