Angular constant for http status codes
Author: 1174557?v=3 yllieth



Angular stuff to easily convert status text into its HTTP code and vice versa.

I only care about real Http statuses, so I used the list from where each code is attached to a RFC.



bower install angular-http-status --save

Once the lib is downloaded,

  1. add a reference in your index.html

    <script type="application/javascript" src="../bower_components/angular-http-status/angular-http-status.js"></script>

  2. add the module in your angular application

    angular .module('YOUR-ANGULAR-APP-NAME', [ 'ngHttpStatus' ]) .config(...

  3. enjoy!


The HttpCodes constant

It's a big object with status text as keys and status codes as values, like:

Once you adds HttpCodes as dependency in a controller / service / ..., you cas use it like:

if (rejection.status === HttpCodes.UNAUTHORIZED) { $state.go('login') }

The HttpStatus factory

Defines the following methods:

  • toString({Number} status) : takes a valid HTTP status code and returns its meaning (undefined if given status isn't in the list)


Here is the code of the controller used for the demo app:

angular .module('demo-angular-http-status', ['ngHttpStatus']) .controller('demoCtrl', function(HttpCodes, HttpStatus) {



DBAD. See the LICENSE for more details.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
comments powered by Disqus
This page was last updated about 3 years ago.