mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-01 03:36:04 +08: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:
@@ -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];
|
||||
}
|
||||
Reference in New Issue
Block a user