By using AngularJS $httpProvider.interceptors we can handle request and response globally.Here I am adding code for response only.
First create one angular factory e.g.
myModule.factory('myResponseInterceptors', function ($q) {
return {
response: function (response) {
// do something on success
if(response.data == null)
{
// Do what ever you want to do
}
return response;
},
responseError: function (response) {
// do something on error
return $q.reject(response);
}
};
});
And add this factory into $httpProvider on your main module config section
myModule.config(function ($httpProvider) {
$httpProvider.interceptors.push('myResponseInterceptors');
});
AngularJs httpPromise response object has following properties
data – {string|Object} – The response body transformed with the transform functions.
status – {number} – HTTP status code of the response.
headers – {function([headerName])} – Header getter function.
config – {Object} – The configuration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.