open-nomad/ui/app/controllers/application.js

72 lines
1.5 KiB
JavaScript
Raw Normal View History

/* eslint-disable ember/no-observers */
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
import { run } from '@ember/runloop';
import { observes } from '@ember-decorators/object';
import { computed } from '@ember/object';
import Ember from 'ember';
import codesForError from '../utils/codes-for-error';
2018-07-31 21:32:17 +00:00
import NoLeaderError from '../utils/no-leader-error';
import classic from 'ember-classic-decorator';
@classic
export default class ApplicationController extends Controller {
@service config;
@service system;
queryParams = [
{
region: 'region',
},
];
region = null;
error = null;
@computed('error')
get errorStr() {
2019-03-26 07:46:44 +00:00
return this.error.toString();
}
@computed('error')
get errorCodes() {
2019-03-26 07:46:44 +00:00
return codesForError(this.error);
}
@computed('errorCodes.[]')
get is403() {
2019-03-26 07:46:44 +00:00
return this.errorCodes.includes('403');
}
@computed('errorCodes.[]')
get is404() {
2019-03-26 07:46:44 +00:00
return this.errorCodes.includes('404');
}
@computed('errorCodes.[]')
get is500() {
2019-03-26 07:46:44 +00:00
return this.errorCodes.includes('500');
}
@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;
}
2018-07-31 21:32:17 +00:00
@observes('error')
throwError() {
if (this.get('config.isDev')) {
run.next(() => {
2019-03-26 07:46:44 +00:00
throw this.error;
});
} 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
});
}
}
}