diff --git a/changelog/14551.txt b/changelog/14551.txt new file mode 100644 index 000000000000..47ef9add25b3 --- /dev/null +++ b/changelog/14551.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Fix issue where UI incorrectly handled API errors when mounting backends +``` \ No newline at end of file diff --git a/ui/app/adapters/secret-engine.js b/ui/app/adapters/secret-engine.js index 1d75aae4273d..40edfc3004f3 100644 --- a/ui/app/adapters/secret-engine.js +++ b/ui/app/adapters/secret-engine.js @@ -61,15 +61,8 @@ export default ApplicationAdapter.extend({ data.id = path; } // first create the engine - try { - await this.ajax(this.url(path), 'POST', { data }); - } catch (e) { - // if error determine if path duplicate or permissions - if (e.httpStatus === 400) { - throw new Error('samePath'); - } - throw new Error('mountIssue'); - } + await this.ajax(this.url(path), 'POST', { data }); + // second post to config try { await this.ajax(this.urlForConfig(path), 'POST', { data: configData }); diff --git a/ui/app/components/mount-backend-form.js b/ui/app/components/mount-backend-form.js index 2433af9bcebb..0493003d97aa 100644 --- a/ui/app/components/mount-backend-form.js +++ b/ui/app/components/mount-backend-form.js @@ -113,22 +113,17 @@ export default Component.extend({ } } - if (!capabilities.get('canUpdate')) { - // if there is no sys/mount issue then error is config endpoint. - this.flashMessages.warning( - 'You do not have access to the config endpoint. The secret engine was mounted, but the configuration settings were not saved.' - ); - // remove the config data from the model otherwise it will save it even if the network request failed. - [this.mountModel.maxVersions, this.mountModel.casRequired, this.mountModel.deleteVersionAfter] = [ - 0, - false, - 0, - ]; - } + let changedAttrKeys = Object.keys(mountModel.changedAttributes()); + const updatesConfig = + mountModel.isV2KV && + (changedAttrKeys.includes('casRequired') || + changedAttrKeys.includes('deleteVersionAfter') || + changedAttrKeys.includes('maxVersions')); + try { yield mountModel.save(); } catch (err) { - if (err.message === 'mountIssue') { + if (err.httpStatus === 403) { this.mountIssue = true; this.set('isFormInvalid', this.mountIssue); this.flashMessages.danger( @@ -136,9 +131,31 @@ export default Component.extend({ ); return; } - this.set('errorMessage', 'This mount path already exist.'); + if (err.errors) { + let errors = err.errors.map((e) => { + if (typeof e === 'object') return e.title || e.message || JSON.stringify(e); + return e; + }); + this.set('errors', errors); + } else if (err.message) { + this.set('errorMessage', err.message); + } else { + this.set('errorMessage', 'An error occurred, check the vault logs.'); + } return; } + if (updatesConfig && !capabilities.get('canUpdate')) { + // config error is not thrown from secret-engine adapter, so handling here + this.flashMessages.warning( + 'You do not have access to the config endpoint. The secret engine was mounted, but the configuration settings were not saved.' + ); + // remove the config data from the model otherwise it will save it even if the network request failed. + [this.mountModel.maxVersions, this.mountModel.casRequired, this.mountModel.deleteVersionAfter] = [ + 0, + false, + 0, + ]; + } let mountType = this.mountType; mountType = mountType === 'secret' ? `${mountType}s engine` : `${mountType} method`; this.flashMessages.success(`Successfully mounted the ${type} ${mountType} at ${path}.`); diff --git a/ui/app/templates/components/mount-backend-form.hbs b/ui/app/templates/components/mount-backend-form.hbs index 58a4c5eaad23..0d9612ca5c59 100644 --- a/ui/app/templates/components/mount-backend-form.hbs +++ b/ui/app/templates/components/mount-backend-form.hbs @@ -21,7 +21,7 @@
- + {{#if this.showEnable}}