-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
error_handler.js
50 lines (43 loc) · 977 Bytes
/
error_handler.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Logger from 'ember-console';
import { isTesting } from './testing';
// To maintain stacktrace consistency across browsers
let getStack = function(error) {
var stack = error.stack;
var message = error.message;
if (stack && stack.indexOf(message) === -1) {
stack = message + '\n' + stack;
}
return stack;
};
let onerror;
// Ember.onerror getter
export function getOnerror() {
return onerror;
}
// Ember.onerror setter
export function setOnerror(handler) {
onerror = handler;
}
let dispatchOverride;
// dispatch error
export function dispatchError(error) {
if (dispatchOverride) {
dispatchOverride(error);
} else {
defaultDispatch(error);
}
}
// allows testing adapter to override dispatch
export function setDispatchOverride(handler) {
dispatchOverride = handler;
}
function defaultDispatch(error) {
if (isTesting()) {
throw error;
}
if (onerror) {
onerror(error);
} else {
Logger.error(getStack(error));
}
}