From e1f26059a767a01d522c942433eecfb862049458 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 1 Mar 2019 09:58:54 -0700 Subject: [PATCH] Convert objects and such to usable strings in rageshake Fixes https://github.com/vector-im/riot-web/issues/7844 --- src/rageshake/rageshake.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rageshake/rageshake.js b/src/rageshake/rageshake.js index 29dbe4f41d..6366392c04 100644 --- a/src/rageshake/rageshake.js +++ b/src/rageshake/rageshake.js @@ -71,6 +71,18 @@ class ConsoleLogger { log(level, ...args) { // We don't know what locale the user may be running so use ISO strings const ts = new Date().toISOString(); + + // Convert objects and errors to helpful things + args = args.map((arg) => { + if (arg instanceof Error) { + return arg.message + (arg.stack ? `\n${arg.stack}` : ''); + } else if (typeof(arg) === 'object') { + return JSON.stringify(arg); + } else { + return arg; + } + }); + // Some browsers support string formatting which we're not doing here // so the lines are a little more ugly but easy to implement / quick to // run.