feat(fe): more suitable text for 401 error

This commit is contained in:
Denis Gukov 2022-01-19 04:03:14 +05:00
parent 948bb8d1c3
commit cab1bd313d

View File

@ -1,7 +1,21 @@
// eslint-disable-next-line import/prefer-default-export
export function getErrorMessage(err) {
if (err.response && err.response.data) {
return err.response.data.error || err.message;
if (err.response) {
if (err.response.data && err.response.data.error) {
return err.response.data.error;
}
if (err.message && !err.message.startsWith('Request failed with status code ')) {
return err.message;
}
switch (err.response.status) {
case 401:
return `${err.response.status} ${err.response.statusText}`;
default:
return err.message;
}
}
return err.message;
}