diff --git a/ui/app/mixins/with-forbidden-state.js b/ui/app/mixins/with-forbidden-state.js new file mode 100644 index 000000000..4b1397e09 --- /dev/null +++ b/ui/app/mixins/with-forbidden-state.js @@ -0,0 +1,18 @@ +import Ember from 'ember'; + +const { Mixin } = Ember; + +export default Mixin.create({ + setupController(controller) { + if (this.get('isForbidden')) { + this.set('isForbidden', undefined); + controller.set('isForbidden', true); + } + this._super(...arguments); + }, + + resetController(controller) { + controller.set('isForbidden', false); + this._super(...arguments); + }, +}); diff --git a/ui/app/utils/notify-forbidden.js b/ui/app/utils/notify-forbidden.js new file mode 100644 index 000000000..433d1fc40 --- /dev/null +++ b/ui/app/utils/notify-forbidden.js @@ -0,0 +1,12 @@ +// An error handler to provide to a promise catch to set a +// forbidden flag on the route +import codesForError from './codes-for-error'; +export default function notifyForbidden(route) { + return error => { + if (codesForError(error).includes('403')) { + route.set('isForbidden', true); + } else { + throw error; + } + }; +}