I'm new to angular and kind of lost right now. I have a provder that handles if server sends response or not and then I do some stuff based on it.
Here is the provider code
define(['angular', '../module'], function (angular, module) {
return module.provider('httpProvider', ['$httpProvider', function ($httpProvider) {
var interceptor = ['$q', '$rootScope', function ($q, $rootScope) {
return {
response: function (response) {
$rootScope.serverError = true;
return response;
},
responseError: function (rejection) {
if (rejection.status === 0) {
$rootScope.serverError = true;
}
return $q.reject(rejection);
},
};
}];
$httpProvider.interceptors.push(interceptor);
}]);
});
And it throws error:
Provider 'httpProvider' must define $get factory method.
Any idea?
EDIT:
Here is how my factory looks now, and its created fine, but I can not inject it into config
define(['angular', './module'], function (angular, module) {
module.factory('httpInterceptor', function () {
var interceptor = ['$q', '$rootScope', function ($q, $rootScope) {
return {
response: function (response) {
$rootScope.serverError = true;
return response;
},
responseError: function (rejection) {
if (rejection.status === 0) {
$rootScope.serverError = true;
}
return $q.reject(rejection);
}
};
}];
return interceptor;
});
});
In module config I use it this way:
$httpProvider.interceptors.push('httpInterceptor');
But it actually push to the array just a string ( who would expect that right? D: ) and nothing is happening. I've changed the factory to always has serverError set to true, so I can test it, but it will actually do nothing, so it means that response or responseError functions are never called.
Any idea?