mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-05-14 15:01:44 +00:00
* 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>
22 lines
526 B
JavaScript
22 lines
526 B
JavaScript
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];
|
|
}
|