|
| 1 | +import angular from 'angular' |
| 2 | + |
1 | 3 | // Include in index.html so that app level exceptions are handled.
|
2 | 4 | // Exclude from testRunner.html which should run exactly what it wants to run
|
3 | 5 | (function () {
|
4 |
| - 'use strict'; |
| 6 | + 'use strict' |
5 | 7 |
|
6 | 8 | angular
|
7 | 9 | .module('blocks.exception')
|
8 | 10 | .provider('exceptionHandler', exceptionHandlerProvider)
|
9 |
| - .config(config); |
| 11 | + .config(config) |
10 | 12 |
|
11 | 13 | /**
|
12 | 14 | * Must configure the exception handling
|
|
16 | 18 | /* jshint validthis:true */
|
17 | 19 | this.config = {
|
18 | 20 | appErrorPrefix: undefined
|
19 |
| - }; |
| 21 | + } |
20 | 22 |
|
21 | 23 | this.configure = function (appErrorPrefix) {
|
22 |
| - this.config.appErrorPrefix = appErrorPrefix; |
23 |
| - }; |
| 24 | + this.config.appErrorPrefix = appErrorPrefix |
| 25 | + } |
24 | 26 |
|
25 | 27 | this.$get = function () {
|
26 |
| - return {config: this.config}; |
27 |
| - }; |
| 28 | + return {config: this.config} |
| 29 | + } |
28 | 30 | }
|
29 | 31 |
|
30 |
| - config.$inject = ['$provide']; |
| 32 | + config.$inject = ['$provide'] |
31 | 33 |
|
32 | 34 | /**
|
33 | 35 | * Configure by setting an optional string value for appErrorPrefix.
|
|
37 | 39 | * @ngInject
|
38 | 40 | */
|
39 | 41 | function config($provide) {
|
40 |
| - $provide.decorator('$exceptionHandler', extendExceptionHandler); |
| 42 | + $provide.decorator('$exceptionHandler', extendExceptionHandler) |
41 | 43 | }
|
42 | 44 |
|
43 |
| - extendExceptionHandler.$inject = ['$delegate', 'exceptionHandler', 'logger']; |
| 45 | + extendExceptionHandler.$inject = ['$delegate', 'exceptionHandler', 'logger'] |
44 | 46 |
|
45 | 47 | /**
|
46 | 48 | * Extend the $exceptionHandler service to also display a toast.
|
|
51 | 53 | */
|
52 | 54 | function extendExceptionHandler($delegate, exceptionHandler, logger) {
|
53 | 55 | return function (exception, cause) {
|
54 |
| - var appErrorPrefix = exceptionHandler.config.appErrorPrefix || ''; |
55 |
| - var errorData = {exception: exception, cause: cause}; |
56 |
| - exception.message = appErrorPrefix + exception.message; |
57 |
| - $delegate(exception, cause); |
| 56 | + var appErrorPrefix = exceptionHandler.config.appErrorPrefix || '' |
| 57 | + var errorData = {exception: exception, cause: cause} |
| 58 | + exception.message = appErrorPrefix + exception.message |
| 59 | + $delegate(exception, cause) |
58 | 60 | /**
|
59 | 61 | * Could add the error to a service's collection,
|
60 | 62 | * add errors to $rootScope, log errors to remote web server,
|
61 | 63 | * or log locally. Or throw hard. It is entirely up to you.
|
62 |
| - * throw exception; |
| 64 | + * throw exception |
63 | 65 | *
|
64 | 66 | * @example
|
65 |
| - * throw { message: 'error message we added' }; |
| 67 | + * throw { message: 'error message we added' } |
66 | 68 | */
|
67 |
| - logger.error(exception.message, errorData); |
68 |
| - }; |
| 69 | + logger.error(exception.message, errorData) |
| 70 | + } |
69 | 71 | }
|
70 |
| -})(); |
| 72 | +})() |
0 commit comments