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

59 lines
1.4 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
import { run } from '@ember/runloop';
import { observer, 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';
export default Controller.extend({
config: service(),
system: service(),
queryParams: {
region: 'region',
},
region: null,
error: null,
errorStr: computed('error', function() {
return this.get('error').toString();
}),
errorCodes: computed('error', function() {
return codesForError(this.get('error'));
}),
is403: computed('errorCodes.[]', function() {
return this.get('errorCodes').includes('403');
}),
is404: computed('errorCodes.[]', function() {
return this.get('errorCodes').includes('404');
}),
is500: computed('errorCodes.[]', function() {
return this.get('errorCodes').includes('500');
}),
2018-07-31 21:32:17 +00:00
isNoLeader: computed('error', function() {
const error = this.get('error');
return error instanceof NoLeaderError;
}),
throwError: observer('error', function() {
if (this.get('config.isDev')) {
run.next(() => {
throw this.get('error');
});
} else if (!Ember.testing) {
2017-12-06 18:32:50 +00:00
run.next(() => {
// eslint-disable-next-line
console.warn('UNRECOVERABLE ERROR:', this.get('error'));
});
}
}),
});