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';
|
|
|
|
import { observer, 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';
|
2017-09-28 17:04:33 +00:00
|
|
|
|
|
|
|
export default Controller.extend({
|
2017-12-15 21:39:18 +00:00
|
|
|
config: service(),
|
2018-08-02 22:56:11 +00:00
|
|
|
system: service(),
|
|
|
|
|
|
|
|
queryParams: {
|
|
|
|
region: 'region',
|
|
|
|
},
|
|
|
|
|
2018-08-08 20:49:04 +00:00
|
|
|
region: null,
|
2017-10-07 00:10:29 +00:00
|
|
|
|
2017-09-28 17:04:33 +00:00
|
|
|
error: null,
|
|
|
|
|
|
|
|
errorStr: computed('error', function() {
|
|
|
|
return this.get('error').toString();
|
|
|
|
}),
|
|
|
|
|
|
|
|
errorCodes: computed('error', function() {
|
2017-10-13 00:40:49 +00:00
|
|
|
return codesForError(this.get('error'));
|
2017-09-28 17:04:33 +00:00
|
|
|
}),
|
|
|
|
|
2017-10-12 23:56:20 +00:00
|
|
|
is403: computed('errorCodes.[]', function() {
|
|
|
|
return this.get('errorCodes').includes('403');
|
|
|
|
}),
|
|
|
|
|
2017-09-28 17:04:33 +00:00
|
|
|
is404: computed('errorCodes.[]', function() {
|
|
|
|
return this.get('errorCodes').includes('404');
|
|
|
|
}),
|
|
|
|
|
|
|
|
is500: computed('errorCodes.[]', function() {
|
|
|
|
return this.get('errorCodes').includes('500');
|
|
|
|
}),
|
2017-10-07 00:10:29 +00:00
|
|
|
|
2018-07-31 21:32:17 +00:00
|
|
|
isNoLeader: computed('error', function() {
|
|
|
|
const error = this.get('error');
|
|
|
|
return error instanceof NoLeaderError;
|
|
|
|
}),
|
|
|
|
|
2017-10-07 00:10:29 +00:00
|
|
|
throwError: observer('error', function() {
|
|
|
|
if (this.get('config.isDev')) {
|
|
|
|
run.next(() => {
|
|
|
|
throw this.get('error');
|
|
|
|
});
|
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
|
|
|
|
console.warn('UNRECOVERABLE ERROR:', this.get('error'));
|
|
|
|
});
|
2017-10-07 00:10:29 +00:00
|
|
|
}
|
|
|
|
}),
|
2017-09-28 17:04:33 +00:00
|
|
|
});
|