2018-05-28 22:57:08 +02:00
|
|
|
/**
|
|
|
|
* Returns error without stack trace for better UI display
|
|
|
|
* @param {Error} err - error
|
2020-01-13 19:36:36 +01:00
|
|
|
* @returns {Error} - Error with clean stack trace.
|
2018-05-28 22:57:08 +02:00
|
|
|
*/
|
2020-05-06 00:19:38 +02:00
|
|
|
export default function cleanErrorStack (err) {
|
2020-08-18 22:06:58 +02:00
|
|
|
let { name } = err
|
2018-05-28 22:57:08 +02:00
|
|
|
name = (name === undefined) ? 'Error' : String(name)
|
|
|
|
|
2019-12-03 15:52:01 +01:00
|
|
|
let msg = err.message
|
2018-05-28 22:57:08 +02:00
|
|
|
msg = (msg === undefined) ? '' : String(msg)
|
|
|
|
|
|
|
|
if (name === '') {
|
|
|
|
err.stack = err.message
|
|
|
|
} else if (msg === '') {
|
|
|
|
err.stack = err.name
|
|
|
|
} else {
|
|
|
|
err.stack = err.name + ': ' + err.message
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|