2018-05-28 22:57:08 +02:00
|
|
|
/**
|
|
|
|
* Returns error without stack trace for better UI display
|
|
|
|
* @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) {
|
2020-08-18 22:06:58 +02:00
|
|
|
let { name } = err
|
2020-11-03 00:41:28 +01:00
|
|
|
name = name === undefined ? 'Error' : String(name)
|
2018-05-28 22:57:08 +02:00
|
|
|
|
2019-12-03 15:52:01 +01:00
|
|
|
let msg = err.message
|
2020-11-03 00:41:28 +01:00
|
|
|
msg = msg === undefined ? '' : String(msg)
|
2018-05-28 22:57:08 +02:00
|
|
|
|
|
|
|
if (name === '') {
|
|
|
|
err.stack = err.message
|
|
|
|
} else if (msg === '') {
|
|
|
|
err.stack = err.name
|
|
|
|
} else {
|
2020-08-19 18:27:05 +02:00
|
|
|
err.stack = `${err.name}: ${err.message}`
|
2018-05-28 22:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|