Skip to content

Commit

Permalink
Simplified error passing for policy editor
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Dec 15, 2022
1 parent 926e9a2 commit 0200e2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .changelog/15435.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: The web UI now provides a Token Management interface for management users on policy pages
```
14 changes: 4 additions & 10 deletions ui/app/components/policy-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Component from '@glimmer/component';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import messageForError from 'nomad-ui/utils/message-from-adapter-error';

export default class PolicyEditorComponent extends Component {
@service flashMessages;
Expand All @@ -22,14 +21,9 @@ export default class PolicyEditorComponent extends Component {
try {
const nameRegex = '^[a-zA-Z0-9-]{1,128}$';
if (!this.policy.name?.match(nameRegex)) {
throw {
errors: [
{
detail:
'Policy name must be 1-128 characters long and can only contain letters, numbers, and dashes.',
},
],
};
throw new Error(
`Policy name must be 1-128 characters long and can only contain letters, numbers, and dashes.`
);
}

const shouldRedirectAfterSave = this.policy.isNew;
Expand Down Expand Up @@ -60,7 +54,7 @@ export default class PolicyEditorComponent extends Component {
} catch (error) {
this.flashMessages.add({
title: `Error creating Policy ${this.policy.name}`,
message: messageForError(error),
message: error,
type: 'error',
destroyOnClick: false,
sticky: true,
Expand Down

0 comments on commit 0200e2d

Please sign in to comment.