Common code for handling 403s in routes

This commit is contained in:
Michael Lange 2017-10-24 16:06:58 -07:00
parent fce7440f34
commit 225817583f
2 changed files with 30 additions and 0 deletions

View file

@ -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);
},
});

View file

@ -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;
}
};
}