2020-06-09 21:03:28 +00:00
|
|
|
/* eslint-disable ember/no-observers */
|
2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import { run } from '@ember/runloop';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { observes } from '@ember-decorators/object';
|
|
|
|
import { computed } from '@ember/object';
|
2017-09-28 17:04:33 +00:00
|
|
|
import Ember from 'ember';
|
2017-10-13 00:40:49 +00:00
|
|
|
import codesForError from '../utils/codes-for-error';
|
2018-07-31 21:32:17 +00:00
|
|
|
import NoLeaderError from '../utils/no-leader-error';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-28 17:04:33 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
export default class ApplicationController extends Controller {
|
|
|
|
@service config;
|
|
|
|
@service system;
|
2018-08-02 22:56:11 +00:00
|
|
|
|
2020-06-11 13:38:33 +00:00
|
|
|
queryParams = [
|
|
|
|
{
|
|
|
|
region: 'region',
|
|
|
|
},
|
|
|
|
];
|
2018-08-02 22:56:11 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
region = null;
|
2017-10-07 00:10:29 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
error = null;
|
2017-09-28 17:04:33 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('error')
|
|
|
|
get errorStr() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.error.toString();
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-28 17:04:33 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('error')
|
|
|
|
get errorCodes() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return codesForError(this.error);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-28 17:04:33 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('errorCodes.[]')
|
|
|
|
get is403() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.errorCodes.includes('403');
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-10-12 23:56:20 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('errorCodes.[]')
|
|
|
|
get is404() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.errorCodes.includes('404');
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-28 17:04:33 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('errorCodes.[]')
|
|
|
|
get is500() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.errorCodes.includes('500');
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-10-07 00:10:29 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('error')
|
|
|
|
get isNoLeader() {
|
2019-03-26 07:46:44 +00:00
|
|
|
const error = this.error;
|
2018-07-31 21:32:17 +00:00
|
|
|
return error instanceof NoLeaderError;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-07-31 21:32:17 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@observes('error')
|
|
|
|
throwError() {
|
2017-10-07 00:10:29 +00:00
|
|
|
if (this.get('config.isDev')) {
|
|
|
|
run.next(() => {
|
2019-03-26 07:46:44 +00:00
|
|
|
throw this.error;
|
2017-10-07 00:10:29 +00:00
|
|
|
});
|
2017-12-12 00:20:13 +00:00
|
|
|
} else if (!Ember.testing) {
|
2017-12-06 18:32:50 +00:00
|
|
|
run.next(() => {
|
|
|
|
// eslint-disable-next-line
|
2019-03-26 07:46:44 +00:00
|
|
|
console.warn('UNRECOVERABLE ERROR:', this.error);
|
2017-12-06 18:32:50 +00:00
|
|
|
});
|
2017-10-07 00:10:29 +00:00
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|