* @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)
| 86 | */ |
| 87 | |
| 88 | function minErr(module, ErrorConstructor) { |
| 89 | ErrorConstructor = ErrorConstructor || Error; |
| 90 | return function() { |
| 91 | var code = arguments[0], |
| 92 | template = arguments[1], |
| 93 | message = '[' + (module ? module + ':' : '') + code + '] ', |
| 94 | templateArgs = sliceArgs(arguments, 2).map(function(arg) { |
| 95 | return toDebugString(arg, minErrConfig.objectMaxDepth); |
| 96 | }), |
| 97 | paramPrefix, i; |
| 98 | |
| 99 | message += template.replace(/\{\d+\}/g, function(match) { |
| 100 | var index = +match.slice(1, -1); |
| 101 | |
| 102 | if (index < templateArgs.length) { |
| 103 | return templateArgs[index]; |
| 104 | } |
| 105 | |
| 106 | return match; |
| 107 | }); |
| 108 | |
| 109 | message += '\nhttp://errors.angularjs.org/1.6.7/' + |
| 110 | (module ? module + '/' : '') + code; |
| 111 | |
| 112 | for (i = 0, paramPrefix = '?'; i < templateArgs.length; i++, paramPrefix = '&') { |
| 113 | message += paramPrefix + 'p' + i + '=' + encodeURIComponent(templateArgs[i]); |
| 114 | } |
| 115 | |
| 116 | return new ErrorConstructor(message); |
| 117 | }; |
| 118 | } |
| 119 | |
| 120 | /* We need to tell ESLint what variables are being exported */ |
| 121 | /* exported |
no test coverage detected