From the John Papa style guide for angularjs 1.x. I see the below implementation for an ecxeption catcher. however there is not an example of usage. Could someone provide some examples how to use this in controllers, factories or service methods?
Exception Catchers [Style Y111]
Create a factory that exposes an interface to catch and gracefully handle exceptions.
Why?: Provides a consistent way to catch exceptions that may be thrown in your code (e.g. during XHR calls or promise failures).
/* recommended */
angular
.module('blocks.exception')
.factory('exception', exception);
exception.$inject = ['logger'];
function exception(logger) {
var service = {
catcher: catcher
};
return service;
function catcher(message) {
return function(reason) {
logger.error(message, reason);
};
}
}