Merge pull request #3736 from codyrancher/uncaught-errors

Make unhandled exceptions display the fail whale
This commit is contained in:
Westly Wright 2020-02-04 08:38:21 -07:00 committed by GitHub
commit c3808dd0d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import { run } from '@ember/runloop';
export default Route.extend({
storeReset: service(),
@ -12,6 +13,13 @@ export default Route.extend({
afterModel(model) {
if ( model ) {
this.get('storeReset').reset();
// This ensures the loading over/underlays are hidden even if a failure
// happens in the middle of loading.
run.scheduleOnce('afterRender', function() { // eslint-disable-line
$('#loading-underlay').hide(); // eslint-disable-line
$('#loading-overlay').hide(); // eslint-disable-line
});
} else {
this.transitionTo('authenticated');
}

View File

@ -0,0 +1,20 @@
export function initialize(application) {
const errorHandler = (message, file, line, column, error) => {
const router = application.__container__.lookup('router:main');
const controller = application.__container__.lookup('controller:application');
controller.setProperties({ error });
router.transitionTo('failWhale');
}
window.onerror = errorHandler;
window.addEventListener('unhandledrejection', () => {
errorHandler(null, null, null, null, 'Promise was rejected.');
});
}
export default {
name: 'uncaught-exceptions',
initialize
};