Skip to content

Commit 45a6dd3

Browse files
felixbuenemannmansona
authored andcommitted
Fix ember v6 deprecate-import-onerror-from-ember deprecation
1 parent 1c47054 commit 45a6dd3

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Ember from 'ember';
1+
import { getOnerror, setOnerror } from '@ember/-internals/error-handling';
22

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

1111
initialize: function () {
12-
if (!Ember.onerror) {
12+
if (!getOnerror()) {
1313
// if no onerror handler is defined, define one for fastboot environments
14-
Ember.onerror = function (err) {
14+
setOnerror(function (err) {
1515
const errorMessage = `There was an error running your app in fastboot. More info about the error: \n ${err.stack || err}`;
1616
console.error(errorMessage);
17-
};
17+
});
1818
}
1919
},
2020
};

test-packages/test-scenarios/oneerror-per-visit-test.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ appScenarios
2424
});
2525
});`,
2626
'instance-initializers': {
27-
'setup-onerror.js': `import Ember from 'ember';
27+
'setup-onerror.js': `import { setOnerror } from '@ember/-internals/error-handling';
2828
export function initialize(owner) {
2929
let isFastBoot = typeof 'FastBoot' !== 'undefined';
3030
let fastbootRequestPath;
@@ -36,12 +36,12 @@ appScenarios
3636
3737
console.log('setting up error handler ' + fastbootRequestPath);
3838
39-
Ember.onerror = function (error) {
39+
setOnerror(function (error) {
4040
if (isFastBoot) {
4141
error.fastbootRequestPath = fastbootRequestPath;
4242
throw error;
4343
}
44-
};
44+
});
4545
}
4646
4747
export default {
@@ -52,12 +52,15 @@ appScenarios
5252
routes: {
5353
'application.js': `import Route from '@ember/routing/route';
5454
import { action } from '@ember/object';
55-
import Ember from 'ember';
55+
import { getOnerror } from '@ember/-internals/error-handling';
5656
5757
export default class ApplicationRoute extends Route {
5858
@action
5959
error(err) {
60-
Ember.onerror(err);
60+
const onerror = getOnerror();
61+
if (onerror) {
62+
onerror(err);
63+
}
6164
}
6265
}
6366
`,

0 commit comments

Comments
 (0)