2018-05-28 22:57:08 +02:00
|
|
|
/**
|
|
|
|
* Returns error without stack trace for better UI display
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
2018-05-28 22:57:08 +02:00
|
|
|
* @param {Error} err - error
|
2020-11-10 18:30:41 +01:00
|
|
|
* @returns {Error} Error with clean stack trace.
|
2018-05-28 22:57:08 +02:00
|
|
|
*/
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function cleanErrorStack(err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
let { name } = err;
|
|
|
|
name = name === undefined ? 'Error' : String(name);
|
2018-05-28 22:57:08 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let msg = err.message;
|
|
|
|
msg = msg === undefined ? '' : String(msg);
|
2018-05-28 22:57:08 +02:00
|
|
|
|
|
|
|
if (name === '') {
|
2021-02-04 19:15:23 +01:00
|
|
|
err.stack = err.message;
|
2018-05-28 22:57:08 +02:00
|
|
|
} else if (msg === '') {
|
2021-02-04 19:15:23 +01:00
|
|
|
err.stack = err.name;
|
2021-09-22 19:41:23 +02:00
|
|
|
} else if (!err.stack) {
|
2021-02-04 19:15:23 +01:00
|
|
|
err.stack = `${err.name}: ${err.message}`;
|
2018-05-28 22:57:08 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return err;
|
2018-05-28 22:57:08 +02:00
|
|
|
}
|