aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/cleanErrorStack.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/lib/cleanErrorStack.js')
-rw-r--r--app/scripts/lib/cleanErrorStack.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/scripts/lib/cleanErrorStack.js b/app/scripts/lib/cleanErrorStack.js
new file mode 100644
index 000000000..fe1bfb0ce
--- /dev/null
+++ b/app/scripts/lib/cleanErrorStack.js
@@ -0,0 +1,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