import Logger from 'ember-console';
import { isTesting } from './testing';

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(error.stack);
  }
}

@@ -69,16 +69,262 @@
 ting';%0A%0A
+// To maintain stacktrace consistency across browsers%0Alet getStack = function(error) %7B%0A  var stack = error.stack;%0A  var message = error.message;%0A%0A  if (stack.indexOf(message) === -1) %7B%0A    stack = message + '%5Cn' + stack;%0A  %7D%0A%0A  return stack;%0A%7D;%0A%0A
 let oner
@@ -937,27 +937,31 @@
 r.error(
-error.stack
+getStack(error)
 );%0A  %7D%0A%7D

Fix Error object's stacktrace inconsistency across browsers