MCPcopy
hub / github.com/angular-ui/ui-router / minErr

Function minErr

test/angular/1.6/angular.js:88–127  ·  view source on GitHub ↗

* @description * * This object provides a utility for producing rich Error messages within * AngularJS. 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 exampl

(module, ErrorConstructor)

Source from the content-addressed store, hash-verified

86 */
87
88function minErr(module, ErrorConstructor) {
89 ErrorConstructor = ErrorConstructor || Error;
90
91 var url = 'https://errors.angularjs.org/1.6.10/';
92 var regex = url.replace('.', '\\.') + '[\\s\\S]*';
93 var errRegExp = new RegExp(regex, 'g');
94
95 return function() {
96 var code = arguments[0],
97 template = arguments[1],
98 message = '[' + (module ? module + ':' : '') + code + '] ',
99 templateArgs = sliceArgs(arguments, 2).map(function(arg) {
100 return toDebugString(arg, minErrConfig.objectMaxDepth);
101 }),
102 paramPrefix, i;
103
104 // A minErr message has two parts: the message itself and the url that contains the
105 // encoded message.
106 // The message's parameters can contain other error messages which also include error urls.
107 // To prevent the messages from getting too long, we strip the error urls from the parameters.
108
109 message += template.replace(/\{\d+\}/g, function(match) {
110 var index = +match.slice(1, -1);
111
112 if (index < templateArgs.length) {
113 return templateArgs[index].replace(errRegExp, '');
114 }
115
116 return match;
117 });
118
119 message += '\n' + url + (module ? module + '/' : '') + code;
120
121 for (i = 0, paramPrefix = '?'; i < templateArgs.length; i++, paramPrefix = '&') {
122 message += paramPrefix + 'p' + i + '=' + encodeURIComponent(templateArgs[i]);
123 }
124
125 return new ErrorConstructor(message);
126 };
127}
128
129/* We need to tell ESLint what variables are being exported */
130/* exported

Callers 10

angular.jsFile · 0.70
setupModuleLoaderFunction · 0.70
cacheFactoryFunction · 0.70
addIdentifierFunction · 0.70
$httpFunction · 0.70
qFactoryFunction · 0.70
$RootScopeProviderFunction · 0.70
filterFilterFunction · 0.70
orderByFilterFunction · 0.70
patternDirectiveFunction · 0.70

Calls 2

sliceArgsFunction · 0.70
toDebugStringFunction · 0.70

Tested by

no test coverage detected