Looking at this AuthInterceptor from this helpful answer, how are the request and response key's used in the returned JSON object?
Also, what's the meaning of return config || $q.when(config)? I understand that the second part is returned if config is null or undefined, but what does $q.when(config) mean in this code?
myApp.factory('AuthInterceptor', function ($window, $q) {
return {
'request': function(config) {
config.headers = config.headers || {};
if ($window.sessionStorage.getItem('token')) {
config.headers.Authorization = $window.sessionStorage.getItem('token');
}
return config || $q.when(config);
},
'response': function(response) {
if(response.status === 401) {
$location('/login');
}
return response || $q.when(response);
}
};
});
I typed out the above linked answer. It worked for me, but I don't understand how it's used.