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 Component from '@ember/component';
import { task } from 'ember-concurrency'; import { task } from 'ember-concurrency';
import { ForbiddenError } from '@ember-data/adapter/error';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error'; import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
export default Component.extend({ export default Component.extend({
@ -15,9 +16,11 @@ export default Component.extend({
yield this.get('job.latestDeployment.content').promote(); yield this.get('job.latestDeployment.content').promote();
} catch (err) { } catch (err) {
let message = messageFromAdapterError(err); let message = messageFromAdapterError(err);
if (!message || message === 'Forbidden') {
if (err instanceof ForbiddenError) {
message = 'Your ACL token does not grant permission to promote deployments.'; message = 'Your ACL token does not grant permission to promote deployments.';
} }
this.handleError({ this.handleError({
title: 'Could Not Promote Deployment', title: 'Could Not Promote Deployment',
description: message, description: message,

View File

@ -1,5 +1,6 @@
import Component from '@ember/component'; import Component from '@ember/component';
import { task } from 'ember-concurrency'; import { task } from 'ember-concurrency';
import { ForbiddenError } from '@ember-data/adapter/error';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error'; import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
export default Component.extend({ export default Component.extend({
@ -38,7 +39,8 @@ export default Component.extend({
job.set('status', 'running'); job.set('status', 'running');
} catch (err) { } catch (err) {
let message = messageFromAdapterError(err); let message = messageFromAdapterError(err);
if (!message || message === 'Forbidden') {
if (err instanceof ForbiddenError) {
message = 'Your ACL token does not grant permission to stop jobs.'; message = 'Your ACL token does not grant permission to stop jobs.';
} }