From 1f82e19e2d69f4e7c688902666861a5fdafeb42e Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Wed, 20 May 2020 22:28:23 -0700 Subject: [PATCH] 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. --- ui/app/components/job-page/parts/latest-deployment.js | 5 ++++- ui/app/components/job-page/parts/title.js | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ui/app/components/job-page/parts/latest-deployment.js b/ui/app/components/job-page/parts/latest-deployment.js index c9d2f3873..dacfd7497 100644 --- a/ui/app/components/job-page/parts/latest-deployment.js +++ b/ui/app/components/job-page/parts/latest-deployment.js @@ -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, diff --git a/ui/app/components/job-page/parts/title.js b/ui/app/components/job-page/parts/title.js index 2e65dfc25..b13702d64 100644 --- a/ui/app/components/job-page/parts/title.js +++ b/ui/app/components/job-page/parts/title.js @@ -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.'; }