@@ -21,10 +21,7 @@ public function __construct(UrlGeneratorInterface $router, $stackTracePath = nul
21
21
$ this ->stackTracePath = $ stackTracePath ;
22
22
}
23
23
24
- /**
25
- * @return array
26
- */
27
- public function getFunctions ()
24
+ public function getFunctions (): array
28
25
{
29
26
return array (
30
27
new TwigFunction ('nelmio_js_error_logger ' , array ($ this , 'initErrorLogger ' ), array ('is_safe ' => array ('html ' , 'js ' ))),
@@ -39,14 +36,14 @@ public function initErrorLogger($level = 'error', $includeScriptTag = true)
39
36
$ addStackTraceJs = <<<JS
40
37
var stackTraceJsModule = (function (basicModule) {
41
38
var stackTraceJs = {};
42
-
39
+
43
40
stackTraceJs.appended = false;
44
41
stackTraceJs.queue = [];
45
42
46
43
stackTraceJs.isScriptPresent = function isScriptPresent() {
47
44
return ((typeof StackTrace !== 'undefined') && (typeof StackTrace.fromError === 'function'));
48
45
};
49
-
46
+
50
47
stackTraceJs.sendLogData = function sendLogData(errorMsg, file, line, col, error) {
51
48
StackTrace.fromError(error).then(
52
49
function(stackframes) {
@@ -75,14 +72,14 @@ function(stackframes) {
75
72
req.setRequestHeader('Content-Type', 'application/json');
76
73
req.send(JSON.stringify(
77
74
{
78
- stack: stackframes,
79
- msg: errorMsg,
80
- level: ' $ level',
75
+ stack: stackframes,
76
+ msg: errorMsg,
77
+ level: ' $ level',
81
78
context: {
82
- file: file,
83
- line: line,
84
- column: col,
85
- userAgent: navigator.userAgent,
79
+ file: file,
80
+ line: line,
81
+ column: col,
82
+ userAgent: navigator.userAgent,
86
83
platform: navigator.platform,
87
84
customContext: basicModule.fetchCustomContext()
88
85
}
@@ -96,8 +93,8 @@ function(stackframes) {
96
93
basicModule.callSimpleLogger(errorMsg, file, line, col, error);
97
94
});
98
95
};
99
-
100
-
96
+
97
+
101
98
stackTraceJs.callStackTraceJs = function callStackTraceJs(errorMsg, file, line, col, error) {
102
99
if (stackTraceJs.isScriptPresent()) {
103
100
stackTraceJs.sendLogData(errorMsg, file, line, col, error);
@@ -109,7 +106,7 @@ function(stackframes) {
109
106
script.src = ' $ this ->stackTracePath ';
110
107
document.documentElement.appendChild(script);
111
108
stackTraceJs.appended = true;
112
-
109
+
113
110
script.onload = function() {
114
111
if (stackTraceJs.isScriptPresent()) {
115
112
if (!this.executed) {
@@ -121,20 +118,20 @@ function(stackframes) {
121
118
continue;
122
119
}
123
120
var entry = queue[i];
124
- stackTraceJs.sendLogData(entry[0], entry[1], entry[2], entry[3], entry[4]);
121
+ stackTraceJs.sendLogData(entry[0], entry[1], entry[2], entry[3], entry[4]);
125
122
}
126
- }
123
+ }
127
124
} else {
128
125
console.log(script);
129
126
this.onerror();
130
127
}
131
128
};
132
-
129
+
133
130
script.onerror = function() {
134
131
console.log("StackTrace loading has failed, call default logger");
135
132
basicModule.callSimpleLogger(errorMsg, file, line, col, error)
136
133
};
137
-
134
+
138
135
script.onreadystatechange = function() {
139
136
var self = this;
140
137
if (this.readyState == "complete" || this.readyState == "loaded") {
@@ -162,15 +159,15 @@ function(stackframes) {
162
159
if (oldErrorHandler) {
163
160
oldErrorHandler(errorMsg, file, line, col, error);
164
161
}
165
-
162
+
166
163
if (typeof stackTraceJsModule !== 'undefined') {
167
164
stackTraceJsModule.callStackTraceJs(errorMsg, file, line, col, error);
168
165
return;
169
166
}
170
-
167
+
171
168
basic.callSimpleLogger(errorMsg, file, line, col, error);
172
169
};
173
-
170
+
174
171
basic.callSimpleLogger = function callSimpleLogger(errorMsg, file, line, col, error) {
175
172
var e = encodeURIComponent;
176
173
@@ -182,22 +179,22 @@ function(stackframes) {
182
179
'&context[browser]=' + e(navigator.userAgent) +
183
180
'&context[page]=' + e(document.location.href) + basic.fetchCustomContext();
184
181
};
185
-
182
+
186
183
basic.fetchCustomContext = function fetchCustomContext() {
187
184
var key,
188
185
e = encodeURIComponent,
189
186
customContext = window.nelmio_js_logger_custom_context,
190
187
customContextStr = '';
191
-
188
+
192
189
if ('object' === typeof customContext) {
193
190
for (key in customContext) {
194
191
customContextStr += '&context[' + e(key) + ']=' + e(customContext[key]);
195
192
}
196
- }
197
-
193
+ }
194
+
198
195
return customContextStr;
199
196
};
200
-
197
+
201
198
return basic;
202
199
}());
203
200
JS ;
0 commit comments