Skip to content

Commit

Permalink
ui: Improve the 403 handling slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
John Cowen committed Oct 19, 2018
1 parent bd17f52 commit d710bd5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions ui-v2/app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default Route.extend({
return true;
},
error: function(e, transition) {
// TODO: Normalize all this better
let error = {
status: e.code || '',
message: e.message || e.detail || 'Error',
Expand All @@ -46,6 +47,20 @@ export default Route.extend({
error = e.errors[0];
error.message = error.title || error.detail || 'Error';
}
// TODO: Unfortunately ember will not maintain the correct URL
// for you i.e. when this happens the URL in your browser location bar
// will be the URL where you clicked on the link to come here
// not the URL where you got the 403 response
// Currently this is dealt with a lot better with the new ACLs system, in that
// if you get a 403 in the ACLs area, the URL is correct
// Moving that app wide right now wouldn't be ideal, therefore simply redirect
// to the ACLs URL instead of maintaining the actual URL, which is better than the old
// 403 page
// To note: Consul only gives you back a 403 if a non-existent token has been sent in the header
// if a token has not been sent at all, it just gives you a 200 with an empty dataset
if (error.status === '403') {
return this.transitionTo('dc.acls.tokens');
}
if (error.status === '') {
error.message = 'Error';
}
Expand Down
8 changes: 7 additions & 1 deletion ui-v2/app/routes/dc/kv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ export default Route.extend(WithKvActions, {
...model,
...{
items: repo.findAllBySlug(get(model.parent, 'Key'), dc).catch(e => {
return this.transitionTo('dc.kv.index');
const status = get(e, 'errors.firstObject.status');
switch (status) {
case '403':
return this.transitionTo('dc.acls.tokens');
default:
return this.transitionTo('dc.kv.index');
}
}),
},
});
Expand Down

0 comments on commit d710bd5

Please sign in to comment.