Skip to content

Commit

Permalink
Don't use generic ACL error messages
Browse files Browse the repository at this point in the history
When the error is actually a 403, an ACL error is appropriate, but when
it isn't, fallback on what the API returns.
  • Loading branch information
DingoEatingFuzz committed Jan 28, 2021
1 parent 9c43a7f commit 44e164c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 24 deletions.
9 changes: 1 addition & 8 deletions ui/app/components/job-page/parts/latest-deployment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Component from '@ember/component';
import { task } from 'ember-concurrency';
import { ForbiddenError } from '@ember-data/adapter/error';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
Expand All @@ -18,15 +17,9 @@ export default class LatestDeployment extends Component {
try {
yield this.get('job.latestDeployment.content').promote();
} catch (err) {
let message = messageFromAdapterError(err);

if (err instanceof ForbiddenError) {
message = 'Your ACL token does not grant permission to promote deployments.';
}

this.handleError({
title: 'Could Not Promote Deployment',
description: message,
description: messageFromAdapterError(err, 'promote deployments'),
});
}
})
Expand Down
11 changes: 2 additions & 9 deletions ui/app/components/job-page/parts/title.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Component from '@ember/component';
import { task } from 'ember-concurrency';
import { ForbiddenError } from '@ember-data/adapter/error';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
Expand All @@ -22,7 +21,7 @@ export default class Title extends Component {
} catch (err) {
this.handleError({
title: 'Could Not Stop Job',
description: 'Your ACL token does not grant permission to stop jobs.',
description: messageFromAdapterError(err, 'stop jobs'),
});
}
})
Expand All @@ -41,15 +40,9 @@ export default class Title extends Component {
// Eagerly update the job status to avoid flickering
job.set('status', 'running');
} catch (err) {
let message = messageFromAdapterError(err);

if (err instanceof ForbiddenError) {
message = 'Your ACL token does not grant permission to stop jobs.';
}

this.handleError({
title: 'Could Not Start Job',
description: message,
description: messageFromAdapterError(err, 'start jobs'),
});
}
})
Expand Down
5 changes: 3 additions & 2 deletions ui/app/components/job-page/periodic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AbstractJobPage from './abstract';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import classic from 'ember-classic-decorator';
import messageForError from 'nomad-ui/utils/message-from-adapter-error';

@classic
export default class Periodic extends AbstractJobPage {
Expand All @@ -11,10 +12,10 @@ export default class Periodic extends AbstractJobPage {

@action
forceLaunch() {
this.job.forcePeriodic().catch(() => {
this.job.forcePeriodic().catch(err => {
this.set('errorMessage', {
title: 'Could Not Force Launch',
description: 'Your ACL token does not grant permission to submit jobs.',
description: messageForError(err, 'submit jobs'),
});
});
}
Expand Down
5 changes: 3 additions & 2 deletions ui/app/controllers/allocations/allocation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { task } from 'ember-concurrency';
import Sortable from 'nomad-ui/mixins/sortable';
import { lazyClick } from 'nomad-ui/helpers/lazy-click';
import { watchRecord } from 'nomad-ui/utils/properties/watch';
import messageForError from 'nomad-ui/utils/message-from-adapter-error';
import classic from 'ember-classic-decorator';

@classic
Expand Down Expand Up @@ -73,7 +74,7 @@ export default class IndexController extends Controller.extend(Sortable) {
} catch (err) {
this.set('error', {
title: 'Could Not Stop Allocation',
description: 'Your ACL token does not grant allocation lifecycle permissions.',
description: messageForError(err, 'manage allocation life cycle'),
});
}
})
Expand All @@ -85,7 +86,7 @@ export default class IndexController extends Controller.extend(Sortable) {
} catch (err) {
this.set('error', {
title: 'Could Not Restart Allocation',
description: 'Your ACL token does not grant allocation lifecycle permissions.',
description: messageForError(err, 'manage allocation life cycle'),
});
}
})
Expand Down
3 changes: 2 additions & 1 deletion ui/app/controllers/allocations/allocation/task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Controller from '@ember/controller';
import { computed as overridable } from 'ember-overridable-computed';
import { task } from 'ember-concurrency';
import classic from 'ember-classic-decorator';
import messageForError from 'nomad-ui/utils/message-from-adapter-error';

@classic
export default class IndexController extends Controller {
Expand All @@ -21,7 +22,7 @@ export default class IndexController extends Controller {
} catch (err) {
this.set('error', {
title: 'Could Not Restart Task',
description: 'Your ACL token does not grant allocation lifecycle permissions.',
description: messageForError(err, 'manage allocation life cycle'),
});
}
})
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/allocation-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ module('Acceptance | allocation detail', function(hooks) {
'Title is descriptive'
);
assert.ok(
/ACL token.+?allocation lifecycle/.test(Allocation.inlineError.message),
/ACL token.+?allocation life cycle/.test(Allocation.inlineError.message),
'Message mentions ACLs and the appropriate permission'
);

Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/task-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ module('Acceptance | task detail', function(hooks) {
assert.ok(Task.inlineError.isShown, 'Inline error is shown');
assert.ok(Task.inlineError.title.includes('Could Not Restart Task'), 'Title is descriptive');
assert.ok(
/ACL token.+?allocation lifecycle/.test(Task.inlineError.message),
/ACL token.+?allocation life cycle/.test(Task.inlineError.message),
'Message mentions ACLs and the appropriate permission'
);

Expand Down

0 comments on commit 44e164c

Please sign in to comment.