Type-check the ForbiddenError rather than ducktype it

Going off of the error message being "Forbidden" was brittle to begin
with and no longer works with Fetch due to the error message coming from
jquery underpinnings that were unobserved by Ember Data's attempted
recreation.
This commit is contained in:
Michael Lange 2020-05-20 22:28:23 -07:00
parent 388bb138c2
commit 1f82e19e2d
2 changed files with 7 additions and 2 deletions

View file

@ -1,5 +1,6 @@
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';
export default Component.extend({
@ -15,9 +16,11 @@ export default Component.extend({
yield this.get('job.latestDeployment.content').promote();
} catch (err) {
let message = messageFromAdapterError(err);
if (!message || message === 'Forbidden') {
if (err instanceof ForbiddenError) {
message = 'Your ACL token does not grant permission to promote deployments.';
}
this.handleError({
title: 'Could Not Promote Deployment',
description: message,

View file

@ -1,5 +1,6 @@
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';
export default Component.extend({
@ -38,7 +39,8 @@ export default Component.extend({
job.set('status', 'running');
} catch (err) {
let message = messageFromAdapterError(err);
if (!message || message === 'Forbidden') {
if (err instanceof ForbiddenError) {
message = 'Your ACL token does not grant permission to stop jobs.';
}