Easily specify error messages and functionality for failed requests :)

Angular Core Dependency: >=1.2.1

Module License: MIT

Added by: Sam Deering





Stars: 4

Watchers: 4

Forks: 0

Module Description


bower install angular-http-error

Error callback generator for $http which makes it easy to provide useful messages matched to HTTP status codes when requests go wrong. The matched error message is dealt with by a globally-specified callback in, which can pass it off to some global user notification UI. See demo for a full explanation of how to use this module.

angular-http-error also works quite well with Restangular's promises, as well as its setErrorInterceptor (see$rootScope, E) {
  E.setOnErrorMessage(function(msg, data) {
    //do something fancy with the message, or use the error response data
  E.setOnErrorResponse(function(status, data, config) {
    //do something fancy with every error that E has produced a callback function for

app.controller('demoCtrl', function($scope, $http, E) {
  $scope.loading = true;
    function success(response){
      //Do something...
    E.handle('Default message when there is no matching status code handler')
     .handle(E.NOT_FOUND, 'Only print me when a 404 is received')
     .handle(E.FORBIDDEN, function(response){console.log('Only execute me when a 403 is received');})
     .handle(E.NOT_FOUND, 'Overrides first E.NOT_FOUND')
     .handle(function(response) {
        $scope.loading = false;
        console.log('Always execute me when something goes wrong');

Module stats last updated: 2015-06-28 11:03:03

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!