aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/cleanErrorStack.js
blob: 8adf55db707b780b2bea04b2dd939714da7e0bf6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * Returns error without stack trace for better UI display
 * @param {Error} err - error
 * @returns {Error} Error with clean stack trace.
 */
function cleanErrorStack (err) {
  var name = err.name
  name = (name === undefined) ? 'Error' : String(name)

  var 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
}

module.exports = cleanErrorStack