2017-09-28 17:04:33 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2017-10-07 00:10:29 +00:00
|
|
|
const { Controller, computed, inject, run, observer } = Ember;
|
2017-09-28 17:04:33 +00:00
|
|
|
|
|
|
|
export default Controller.extend({
|
2017-10-07 00:10:29 +00:00
|
|
|
config: inject.service(),
|
|
|
|
|
2017-09-28 17:04:33 +00:00
|
|
|
error: null,
|
|
|
|
|
|
|
|
errorStr: computed('error', function() {
|
|
|
|
return this.get('error').toString();
|
|
|
|
}),
|
|
|
|
|
|
|
|
errorCodes: computed('error', function() {
|
|
|
|
const error = this.get('error');
|
|
|
|
const codes = [error.code];
|
|
|
|
|
|
|
|
if (error.errors) {
|
|
|
|
error.errors.forEach(err => {
|
|
|
|
codes.push(err.status);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return codes
|
|
|
|
.compact()
|
|
|
|
.uniq()
|
|
|
|
.map(code => '' + code);
|
|
|
|
}),
|
|
|
|
|
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
|
|
|
|
|
|
|
throwError: observer('error', function() {
|
|
|
|
if (this.get('config.isDev')) {
|
|
|
|
run.next(() => {
|
|
|
|
throw this.get('error');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
2017-09-28 17:04:33 +00:00
|
|
|
});
|