2021-04-21 02:38:00 -05:00
|
|
|
import { isString } from 'lodash';
|
2019-02-06 12:42:04 -06:00
|
|
|
|
2020-05-14 10:08:52 -05:00
|
|
|
export function getMessageFromError(err: string | (Error & { data?: any; statusText?: string })): string {
|
2021-04-21 02:38:00 -05:00
|
|
|
if (err && !isString(err)) {
|
2019-02-06 12:42:04 -06:00
|
|
|
if (err.message) {
|
|
|
|
return err.message;
|
|
|
|
} else if (err.data && err.data.message) {
|
|
|
|
return err.data.message;
|
2019-02-06 14:35:01 -06:00
|
|
|
} else if (err.statusText) {
|
|
|
|
return err.statusText;
|
2019-02-06 12:42:04 -06:00
|
|
|
} else {
|
|
|
|
return JSON.stringify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 07:18:56 -05:00
|
|
|
return err as string;
|
2019-02-06 12:42:04 -06:00
|
|
|
}
|