Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ember from 'ember';
import { getOnerror, setOnerror } from '@ember/-internals/error-handling';

/**
* Initializer to attach an `onError` hook to your app running in fastboot. It catches any run loop
Expand All @@ -9,12 +9,12 @@ export default {
name: 'error-handler',

initialize: function () {
if (!Ember.onerror) {
if (!getOnerror()) {
// if no onerror handler is defined, define one for fastboot environments
Ember.onerror = function (err) {
setOnerror(function (err) {
const errorMessage = `There was an error running your app in fastboot. More info about the error: \n ${err.stack || err}`;
console.error(errorMessage);
};
});
}
},
};
13 changes: 8 additions & 5 deletions test-packages/test-scenarios/oneerror-per-visit-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ appScenarios
});
});`,
'instance-initializers': {
'setup-onerror.js': `import Ember from 'ember';
'setup-onerror.js': `import { setOnerror } from '@ember/-internals/error-handling';
export function initialize(owner) {
let isFastBoot = typeof 'FastBoot' !== 'undefined';
let fastbootRequestPath;
Expand All @@ -36,12 +36,12 @@ appScenarios

console.log('setting up error handler ' + fastbootRequestPath);

Ember.onerror = function (error) {
setOnerror(function (error) {
if (isFastBoot) {
error.fastbootRequestPath = fastbootRequestPath;
throw error;
}
};
});
}

export default {
Expand All @@ -52,12 +52,15 @@ appScenarios
routes: {
'application.js': `import Route from '@ember/routing/route';
import { action } from '@ember/object';
import Ember from 'ember';
import { getOnerror } from '@ember/-internals/error-handling';

export default class ApplicationRoute extends Route {
@action
error(err) {
Ember.onerror(err);
const onerror = getOnerror();
if (onerror) {
onerror(err);
}
}
}
`,
Expand Down
Loading