angular
        .module('carfriend')
        .factory("APIInterceptor", aPIInterceptor);

function aPIInterceptor($rootScope, $q) {
    var unauthorized = {
        responseError: function (response) {
            if (response.status === 401) 
                $rootScope.$broadcast('unauthorized');
            return $q.reject(response);
        }
    };
    return unauthorized;
}
;