You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
519 B
22 lines
519 B
/**
|
|
* Returns error without stack trace for better UI display
|
|
* @param {Error} err - error
|
|
* @returns {Error} - Error with clean stack trace.
|
|
*/
|
|
export default function cleanErrorStack(err) {
|
|
let { name } = err
|
|
name = name === undefined ? 'Error' : String(name)
|
|
|
|
let msg = err.message
|
|
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
|
|
}
|
|
|