mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-05-14 15:01:44 +00:00
feat: show generic error message for API response 40x error (#816)
* feat: add generic error for API response 40X Signed-off-by: Andy Lee <andy.lee@suse.com> * refactor: fallback error msg Signed-off-by: Andy Lee <andy.lee@suse.com> * refactor: update error msg Signed-off-by: Andy Lee <andy.lee@suse.com> * refactor: based on comment Signed-off-by: Andy Lee <andy.lee@suse.com> --------- Signed-off-by: Andy Lee <andy.lee@suse.com>
This commit is contained in:
parent
9ce95daf76
commit
7d0f33f31d
@ -8,6 +8,7 @@ import FileSelector, { createOnSelected } from '@shell/components/form/FileSelec
|
||||
|
||||
import { randomStr } from '@shell/utils/string';
|
||||
import CreateEditView from '@shell/mixins/create-edit-view';
|
||||
import { getLoginAwareErrors } from '../utils/error';
|
||||
|
||||
export default {
|
||||
name: 'HarvesterEditKeypair',
|
||||
@ -63,6 +64,14 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
normalizedErrors() {
|
||||
const message = this.t('harvester.virtualMachine.genericLoginError');
|
||||
|
||||
return getLoginAwareErrors(this.errors, message);
|
||||
}
|
||||
},
|
||||
|
||||
methods: { onKeySelected: createOnSelected('publicKey') },
|
||||
};
|
||||
</script>
|
||||
@ -72,10 +81,9 @@ export default {
|
||||
:done-route="doneRoute"
|
||||
:resource="value"
|
||||
:mode="mode"
|
||||
:errors="errors"
|
||||
:errors="normalizedErrors"
|
||||
:apply-hooks="applyHooks"
|
||||
@finish="save"
|
||||
@error="e=>errors=e"
|
||||
>
|
||||
<div class="header mb-20">
|
||||
<FileSelector
|
||||
|
||||
@ -10,6 +10,7 @@ import { _VIEW } from '@shell/config/query-params';
|
||||
|
||||
import { NAMESPACE } from '@shell/config/types';
|
||||
import { HCI } from '../../types';
|
||||
import { getLoginAwareErrors } from '../../utils/error';
|
||||
|
||||
const _NEW = '_NEW';
|
||||
|
||||
@ -214,7 +215,9 @@ export default {
|
||||
buttonCb(true);
|
||||
this.cancel();
|
||||
} catch (err) {
|
||||
this.errors = [err.message];
|
||||
const message = this.t('harvester.virtualMachine.genericLoginError');
|
||||
|
||||
this.errors = getLoginAwareErrors(err, message);
|
||||
buttonCb(false);
|
||||
}
|
||||
},
|
||||
|
||||
@ -726,6 +726,7 @@ harvester:
|
||||
other {Start}
|
||||
} Now
|
||||
createSSHKey: Create a New...
|
||||
genericLoginError: Authentication failed. Please re-log in and try again.
|
||||
installAgent: Install guest agent
|
||||
enableUsb: Enable USB Tablet
|
||||
advancedOptions:
|
||||
|
||||
21
pkg/harvester/utils/error.js
Normal file
21
pkg/harvester/utils/error.js
Normal file
@ -0,0 +1,21 @@
|
||||
const AUTH_ERROR_CODES = [401, 403, 404];
|
||||
|
||||
export function getLoginAwareErrors(err, message = '') {
|
||||
const errors = Array.isArray(err) ? err : (err ? [err] : []);
|
||||
|
||||
if (!errors.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const generic = message;
|
||||
|
||||
if (errors.some((e) => AUTH_ERROR_CODES.includes(e?._status || e?.response?.status))) {
|
||||
return [generic];
|
||||
}
|
||||
|
||||
const msgs = errors
|
||||
.map((e) => (typeof e === 'string' ? e : (e?.message || e?._statusText || '')))
|
||||
.filter(Boolean);
|
||||
|
||||
return msgs.length ? msgs : [generic];
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user