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
|
|
|
*/
|
2018-07-03 00:49:33 +02:00
|
|
|
function cleanErrorStack (err) {
|
2019-12-03 15:52:01 +01:00
|
|
|
let name = err.name
|
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
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export default cleanErrorStack
|