-
Notifications
You must be signed in to change notification settings - Fork 784
/
onerror.js
33 lines (30 loc) 路 1.28 KB
/
onerror.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import config from "./config";
import onUncaughtException from "./on-uncaught-exception";
/**
* Handle a window.onerror error.
*
* If there is a current test that sets the internal `ignoreGlobalErrors` field
* (such as during `assert.throws()`), then the error is ignored and native
* error reporting is suppressed as well. This is because in browsers, an error
* can sometimes end up in `window.onerror` instead of in the local try/catch.
* This ignoring of errors does not apply to our general onUncaughtException
* method, nor to our `unhandledRejection` handlers, as those are not meant
* to receive an "expected" error during `assert.throws()`.
*
* @see <https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror>
* @param {Object} details
* @param {string} details.message
* @param {string} details.fileName
* @param {number} details.lineNumber
* @param {string|undefined} [details.stacktrace]
* @return {bool} True if native error reporting should be suppressed.
*/
export default function onWindowError( details ) {
if ( config.current && config.current.ignoreGlobalErrors ) {
return true;
}
const err = new Error( details.message );
err.stack = details.stacktrace || details.fileName + ":" + details.lineNumber;
onUncaughtException( err );
return false;
}