Skip to content

Instantly share code, notes, and snippets.

@deborasetton
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save deborasetton/37ee11991e8a68717957 to your computer and use it in GitHub Desktop.

Select an option

Save deborasetton/37ee11991e8a68717957 to your computer and use it in GitHub Desktop.
Stuff to refer to later
/**
* References:
* [1] https://docs.angularjs.org/api/ng/service/$http#interceptors
* [2] http://www.webdeveasy.com/interceptors-in-angularjs-and-useful-examples/
*
*/
function toasterInterceptor($q, $log, toaster) {
var interceptor = {
request: function (config) {
$log.info("♢ " + config['method'] + ' ' + config['url']);
return config;
},
requestError: function (rejection) {
$log.error("Request error!");
return $q.reject(rejection);
},
response: function (response) {
$log.info("♦ " + response.config['method'] + ' ' + response.config['url'] + ' | ' + response.status + '(' + response.statusText + ')');
return response;
},
responseError: function (rejection) {
$log.error("→ " + rejection.config['method'] + ' ' + rejection.config['url'] + ' | ' + rejection.status + '(' + rejection.statusText + ')');
toaster.pop('error', null, 'Something went wrong');
return $q.reject(rejection);
}
};
return interceptor;
}
# Get something across all indices by TYPE and ID.
/_all/TYPE/_search?q=id:ID
// Gist with some stuff to refer to later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment