Common code for handling 403s in routes
This commit is contained in:
parent
fce7440f34
commit
225817583f
|
@ -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);
|
||||
},
|
||||
});
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue