Skip to content Skip to sidebar Skip to footer

For Which Status Codes Does The Promise Resolve

I want to clarify for which http status codes the promise from $http is resolved and for which it is rejected. As I understand it it resolves only in the case of 200, and the rest

Solution 1:

Edit :

For AngularJS

A response status code between 200 and 299 is considered a success status and will result in the success callback being called. Any response status code outside of that range is considered an error status and will result in the error callback being called.

Source : https://github.com/angular/angular.js/blob/master/src/ng/http.js

Solution 2:

As Bergi pointed out in the comments to your question, the answer lies in the source code. There is a private function in $http called isSuccess, which looks like this:

functionisSuccess(status) {
  return200 <= status && status < 300;
}

It's used in a couple of places in that file, but the important one for our purposes is this:

(isSuccess(status) ? deferred.resolve : deferred.reject)({ //...

So there's your answer! Any status code in the 2** (two-hundred-and-something) range is a success and will resolve the promise that $http wraps around the XHR, anything else is a failure and will reject it.

It's also now explained in the docs for $http.

Post a Comment for "For Which Status Codes Does The Promise Resolve"