(function () { 'use strict'; angular.module('app.service') .factory('$exceptionHandler', ['$log', '$window', 'cfg', function ($log, $window, cfg) { function formatError(arg) { if (arg instanceof Error) { if (arg.stack) { arg = (arg.message && arg.stack.indexOf(arg.message) === -1) ? 'Error: ' + arg.message + '\n' + arg.stack : arg.stack; } else if (arg.sourceURL) { arg = arg.message + '\n' + arg.sourceURL + ':' + arg.line; } } return arg; } return function (exception, cause) { $log.error.apply($log, arguments); if (cfg.debug && 'ontouchstart' in document.documentElement) { alert('Exception: ' + formatError(exception)); } }; }]); })();