* @description * * This object provides a utility for producing rich Error messages within * Angular. It can be called as follows: * * var exampleMinErr = minErr('example'); * throw exampleMinErr('one', 'This {0} is {1}', foo, bar); * * The above creates an instance of minErr in the example
(module, ErrorConstructor)
| 36 | */ |
| 37 | |
| 38 | function minErr(module, ErrorConstructor) { |
| 39 | ErrorConstructor = ErrorConstructor || Error; |
| 40 | return function() { |
| 41 | var SKIP_INDEXES = 2; |
| 42 | |
| 43 | var templateArgs = arguments, |
| 44 | code = templateArgs[0], |
| 45 | message = '[' + (module ? module + ':' : '') + code + '] ', |
| 46 | template = templateArgs[1], |
| 47 | paramPrefix, i; |
| 48 | |
| 49 | message += template.replace(/\{\d+\}/g, function(match) { |
| 50 | var index = +match.slice(1, -1), |
| 51 | shiftedIndex = index + SKIP_INDEXES; |
| 52 | |
| 53 | if (shiftedIndex < templateArgs.length) { |
| 54 | return toDebugString(templateArgs[shiftedIndex]); |
| 55 | } |
| 56 | |
| 57 | return match; |
| 58 | }); |
| 59 | |
| 60 | message += '\nhttp://errors.angularjs.org/1.5.11/' + |
| 61 | (module ? module + '/' : '') + code; |
| 62 | |
| 63 | for (i = SKIP_INDEXES, paramPrefix = '?'; i < templateArgs.length; i++, paramPrefix = '&') { |
| 64 | message += paramPrefix + 'p' + (i - SKIP_INDEXES) + '=' + |
| 65 | encodeURIComponent(toDebugString(templateArgs[i])); |
| 66 | } |
| 67 | |
| 68 | return new ErrorConstructor(message); |
| 69 | }; |
| 70 | } |
| 71 | |
| 72 | /* We need to tell ESLint what variables are being exported */ |
| 73 | /* exported |
no test coverage detected