open-nomad/ui/app/controllers/application.js
Michael Lange 4a35f3c5a5 Handle 403s gracefully
- When a list 403s, treat it as if it were empty
- When a single resource 403s, redirect to an application error page
  that has a backdoor link to the tokens page
2017-10-12 17:40:49 -07:00

39 lines
895 B
JavaScript

import Ember from 'ember';
import codesForError from '../utils/codes-for-error';
const { Controller, computed, inject, run, observer } = Ember;
export default Controller.extend({
config: inject.service(),
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');
}),
throwError: observer('error', function() {
if (this.get('config.isDev')) {
run.next(() => {
throw this.get('error');
});
}
}),
});