2018-05-28 22:57:08 +02:00
|
|
|
/**
|
|
|
|
* Returns error without stack trace for better UI display
|
|
|
|
* @param {Error} err - error
|
|
|
|
* @returns {Error} Error with clean stack trace.
|
|
|
|
*/
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = cleanErrorStack
|