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

Function minErr

test/angular/1.7/angular.js:99–140  ·  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

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

Calls 2

sliceArgsFunction · 0.70
toDebugStringFunction · 0.70

Tested by

no test coverage detected